How do you pass a function as a parameter in C?
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C? 9 s 9
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C? 9 s 9
I always mess up how to use const int*, const int * const, and int const * correctly. Is there a set of rules defining what you can and cannot do? I want to know all the do’s and all don’ts in terms of assignments, passing to the functions, etc. 2 21 Read it backwards … Read more
As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it’s because of pointer arithmetic but I still don’t understand. Why does a[5] == 5[a]? 1 19 The C standard defines the … Read more
I’m coming from a Java background and have started working with objects in C++. But one thing that occurred to me is that people often use pointers to objects rather than the objects themselves, for example this declaration: Object *myObject = new Object; rather than: Object myObject; Or instead of using a function, let’s say … Read more
This question already has answers here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? (9 answers) Closed 7 years ago. I’ve been writing C and C++ code for almost twenty years, but there’s one aspect of these languages that I’ve never really understood. I’ve obviously used regular casts i.e. MyClass *m = (MyClass *)ptr; … Read more
What is a smart pointer and when should I use one? 1 14 UPDATE This answer is rather old, and so describes what was ‘good’ at the time, which was smart pointers provided by the Boost library. Since C++11, the standard library has provided sufficient smart pointers types, and so you should favour the use … Read more
What are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast C-style cast (type)value Function-style cast type(value) How does one decide which to use in which specific cases? 9 static_cast is the first cast you should attempt to use. It does things like implicit conversions between types (such as int to float, or pointer to void*), … Read more
I know references are syntactic sugar, so code is easier to read and write. But what is the difference between a pointer variable and a reference variable? 4 42
How can I use pointers in Java?