函数名:函数名代表函数的入口地址。
函数指针:指向函数的指针
typedef函数类型
1.先定义函数类型,通过类型
typedef int f(int,int);//f为函数类型
void fun(int a,int b)
{
printf(“fun(%d,%d)\n”,a,b);
}
void test()
{
f* pfun;
pfun=fun;//函数指针初始化
pfun(1,1);//相当于调用fun()
(*pfun)(2,2);
}
2.定义函数指针类型
typedef int(*f)(int,int);
void fun(int a,int b)
{
printf(“fun(%d,%d)\n”,a,b);
}
void test()
{
f pfun;
pfun=fun;//函数指针初始化
pfun(1,1);//相当于调用fun()
(*pfun)(2,2);
}
3.直接定义函数指针变量
void fun(int a,int b)
{
printf(“fun(%d,%d)\n”,a,b);
}
void test()
{
void(*pfun)(int ,int)=fun;
pfun(1,1);//相当于调用fun()
(*pfun)(2,2);
}