简书链接:c语言函数指针的定义
文章字数:66,阅读全文大约需要1分钟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| int addMethod(int a,int b){ return a+b; } int addLongMethod(long a,long b){ return a+b; } //typedef int (*fun_ptr)(int,int); // 声明一个指向同样参数、返回值的函数指针类型 void funcPointer() {
void* (*p)(int,int)=addMethod;//必须加上*号码。 printf("p,1+2=%d\n",p(1,2));
int (*p1)(long,long)=addLongMethod; printf("p1,5+52=%ld\n",p1(5,52));
int* (*p3)(int,int)=addMethod; printf("p3,1+2=%d\n",p3(1,2));
int (*p5)(int,int)=addMethod; printf("p5,1+2=%d\n",p5(1,2));
}
|