int foo (int x) {
int (*d)(int *) = foo; //what is the meaning of this line?
...
}
this is an old practice question from my school, but i couldn’t find the solution for it.
Is it initializing a variable to a function?
>Solution :
This record
int (*d)(int *) = foo;
is a declaration of the function pointer d to function that has the return type int and one parameter of the type int *. This pointer is initialized by the address of the function foo (the function designator is implicitly converted to pointer to it).
Pay attention to that either the function foo should be declared like
int foo (int *x) {
or the pointer should be declared like
int (*d)(int ) = foo;
Otherwise in this declaration
int (*d)(int *) = foo;
there are used incompatible pointer types.