4.函数指针
函数指针用来存放函数地址
void(*p)(int,int) = &test;
实例:
int add(int x,int y) { printf("%d ", x + y); } int main() { int (*p)(int,int) = &add; p(3, 4); (*p)(3, 4); (**p)(3, 4); (***p)(3, 4); }
看出p *p **p ***p,都是该函数。
5.函数指针数组
用来存放函数指针的数组
int add(int x,int y) { printf("%d ", x + y); } int test1(int x, int y) { printf("%d ", x - y); } int test2(int x, int y) { printf("%d ", x * y); } int main() { int (*p1)(int, int) = &add;//函数指针 int (*p2)(int, int) = &test1;//函数指针 int (*p3)(int, int) = &test2;//函数指针 int (*pp[3])(int, int) = { p1,p2,p3 };//函数指针数组 }
6.指向函数指针数组的指针
用来存放函数指针数组的地址
int add(int x,int y) { printf("%d ", x + y); } int test1(int x, int y) { printf("%d ", x - y); } int test2(int x, int y) { printf("%d ", x * y); } int main() { int (*p1)(int, int) = &add;//函数指针 int (*p2)(int, int) = &test1;//函数指针 int (*p3)(int, int) = &test2;//函数指针 int (*pp[3])(int, int) = { p1,p2,p3 };//函数指针数组 int(*(*ppp)[3])(int, int) = &pp;//指向函数指针数组的指针 }
后续会对该文章内容进行详细补充