p
is:
typedef int (*p) ();
foo() is:
int foo(){
}
p
type variable is f
:
p f = &foo;
how to call using pointer:
(*f)();
Example code:
#include<stdio.h>
int foo(){
printf("\n In FOO\n");
return 4;
}
typedef int(*p)();
int main(){
p f = &foo;
int i = (*f)();
printf("\n i = %d\n", i);
return 1;
}
you can find it is working on codepad.
note: you can simply assign like p f = foo;
and call like f()
the second form you can find here on codepad
Edit: As @Akash commented:
it compiles and runs like:
~$ gcc x.c -Wall
~$ ./a.out
In FOO
i = 4
Here is a project to help explain the usefulness of function pointers.