the function pointer points to the code area, and the normal pointer points to the data area. The function pointer is defined as follows:
return Type (* function pointer variable) (parameter table)For example, Void (*PF) () points to a function such as void f (). examples of using function pointers:
void open ();//declaration of several functions void print (); void exit (); void (*pfs[]) () ={open,print,exit};//function pointer array int main () {int i;void (*PF) () ;p F=open; (*PF) ();//////calls open () for (i=0;i<3;i++)////calls open (), print (), exit () function (*pfs[i]) ();} void Open () {printf ("open\n");} void print () {printf ("print\n");} void exit () {printf ("exit\n");}
As you can see from this example, the function name itself is the address of the function code area.There are several definitions that are confusing, consider the following definitions:
void (*getinterrupt (int No)) (), void setinterrupt (int no,void (*PF)); LRESULT (*lpfnwndproc) (Hwnd,unit,wparm,lparam);
The first statement indicates that aGetinterrupt's prototype declares that it has an int type parameter, and the return value is a pointer to a void f () function. The second declaration represents a functionSetinterrupt's prototype declaration, the return value is void, it has two parameters, the type is int and a pointer to the void F () function. the third declaration defines a pointer variableLpfnwndproc, pointing shape asthe function of LRESULT WndProc (Hwnd,unit,wparm,lparam).
C Language Advanced programming--function pointers