Function pointer,
1. First, let's talk about functions.
In fact, each function name is the function entry address, as shown in:
0x4013B0 is the entry address of the func () function. As you can see, func AND & func have the same address.
2. Use the function pointer to point to the above func () function.
Instance 1 is as follows:
#include "stdio.h"
int func (int x)
{
return x;
}
int main ()
{
int (* FP) (int); // Define FP function pointer
FP = func; // FP points to the address of func
printf ("% d \ n", FP (1));
printf ("% p,% p \ n", FP, func);
return 0;
}
Output result:
1 // call func () function
004013B0,004013B0
2) When typedef is used, the function pointer uses the following:
#include "stdio.h"
int func (int x)
{
return x;
}
typedef int (* FP) (int); // Use declared function pointer type FP
int main ()
{
FP a; // Define function pointer a via FP
a = func; // a points to the address of func
printf ("% d \ n", a (1));
printf ("% p,% p \ n", a, func);
return 0;
}