下面是验证回调函数原理的代码,他们在windows和linux下均验证通过
``` #include//int demo(char *p)
//CallBackFun是一个函数指针,它指向类似于demo一样的函数(返回值和形参一致)
typedef int (*CallBackFun)(char *p);
//函数A
int Afun(char *p)
{
printf(“Afun 回调打印出字符%s!\n”, p);
return 0;
}
//函数C
int Cfun(char *p)
{
printf(“Cfun 回调打印:%s, Nice to meet you!\n”, p);
return 0;
}
//形参中带有函数指针
int call(CallBackFun pCallBack, char *p)
{
printf(“call 直接打印出字符%s!\n”, p);
pCallBack§;
return 0;
}
//形参中带有函数指针
int call3(char *p, CallBackFun pCallBack)
{
printf("--------------\n", p);
pCallBack§;
}
int main(int argc, char **argv)
{
char *p = “hello”;
call(Afun, p);
call(Cfun, p);
call3(p, Afun);
call3(p, Cfun);
system("pause");
return 0;
}