本文共 671 字,大约阅读时间需要 2 分钟。
所以a是个5个元素的数组,每个元素为函数指针.
可用代码验证:
#include#include int* (*a[5])(int,char*);int *foo(int n, char *s){ int *p; p = (int *)malloc(sizeof(int)); *p = n + atoi(s); return p;}int main(int argc, char *argv[]){ int *p; a[0] = &foo; p = (*a[0])(1, "2"); printf("%d\n", *p); return 0;}
输出:
3
顺便把函数指针再复习一下:
#include输出:#include //int* (*a[5])(int,char*);typedef int (*f)(int,char*);f funp;int foo(int n, char *s){ return 10086;}int main(int argc, char *argv[]){ funp = &foo; printf("%x\n",funp); printf("%d\n",(*funp)(6,"test")); return 0;}
3f1000
10086
转载地址:http://keuoo.baihongyu.com/