c语言 函数指针使用
#include <stdio.h>//函数声明int sum(int, int);int product(int, int);int different(int, int);//c语言就是由许多函数组成的,其中main是执行的起点,函数之间互相调用int main() {printf("函数指针使用方法:\n");int a = 10, b = 5;int result = 0;int (*pfun)(int, int); //声明一个函数指针pfun = sum; //指针传递result = pfun(a, b);printf("result: %d\n", result);pfun = different;result = pfun(a, b);printf("result: %d\n", result);pfun = product;result = pfun(a, b);printf("result: %d\n", result);printf("\n");//函数指针数组int (*pfuns[3])(int, int); //声明一个函数指针数组 指针是一个变量,函数指针可以像其他变量一样使用pfuns[0] = sum;pfuns[1] = different;pfuns[2] = product;int i = 0;while (i < 3) {result = pfuns[i](a, b);printf("result: %d\n", result);i++;}return 0;}int sum(int x, int y) {return x + y;}int product(int x, int y) {return x * y;}int different(int x, int y) {return x - y;}?