#include <iostream> using namespace std; typedef int (*func)(int a, int b); int call_func(int a, int b) { return a + b; } void function(int a, int b, func f); int main () { function(5, 2, &call_func); system("pause"); } void function(int a, int b, func f) { int sum = (*f)(a, b); std::cout << "Sum = " << sum << std::endl; }
typedef introduces a new name for the type, and I think examples of the typedef int int32
are clear to anyone. Well, what about typedef int (*func)(int a, int b);
in this code, it should substitute int (int a, int b) f
instead of func f
, but substitutes int f (int a, int b), although I do not understand this, but also how he knows what to replace you need func, because it is an incomplete type or name. Description of typedef on the Internet ends with typedef int int32
or just with an example of structures and functions or some other complex types, but without explanation. I do not know what to think anymore, it was somehow easier with define.
float* p = new float[64]
, thenp + 2
points to the array element with index 2, that is, the 8th byte ( and not the 2nd). (3) yes, it is. (4) read my favorite related question . It is in English, but you plow through the text and enjoy it. - VladD