From this question How do function pointers in C work?, I tried it here:
#include <stdio.h>
int add(int a, int b){ return a+b; }
int add2(int(*fp)(int,int)){
return fp(2,3);
}
int (*factory(int n))(int,int){
printf("got params:%i\n",n);
return add;
}
int main(){
int *p(int,int) = factory(5); // it has to be (*p)
printf("%i\n",p(1,2));
}
There was mentioned
the standard says that a function name is converted to the address of the function
So it should work without the parethesis anyway, when it is converted to address.
But it gives error:
function ‘p’ is initialized like a variable
But is should be function pointer, not just function. So how is it with the syntax?