int (*arr[4])(int ,int) ,我们需要把数组名放到*的右边
函数指针数组的⽤途:转移表
可以让代码更加简单前提是函数类型相同
#include<stdio.h>
int add(int x, int y) {return x + y;
}
int sub(int x, int y) {return x - y;
}
int miv(int x, int y) {return x * y;
}
int div(int x, int y) {return x / y;
}
int main() {int a;int (*arr[4])(int, int) = { add,sub,miv,div };do {printf(" * ********************************************\n");printf(" * ***********请输入你的需求**************\n");printf(" * ***********0:退出程序;1:加法**************\n");printf(" * ***********2:减法3:乘法4:除法**************\n");printf(" * **********************************************\n");int x, y;scanf_s("%d", &a);printf("请输入你需要的操作数");scanf_s("%d %d", &x, &y);int f=(*arr[a - 1])(x, y);printf("%d", f);} while (a == 0);
}