声明一个函数指针数组
typedef int (*operation)(int,int);
operation operations[128]={NULL};
或者
int (*operations[128])(int)={NULL};
#include<stdio.h>
int add(int num1, int num2)
{
return num1 + num2;
}
int subtract(int num1, int num2)
{
return num1 - num2;
}
typedef int(*fptrOperation)(int, int);
int main(void)
{
fptrOperation operations[10] = {NULL};
operations[0] = add;
operations[1] = subtract;
printf("%d\n", (operations[0])(5,6));
printf("%d\n", (operations[1])(5,6));
return 0;
}