函数指针的用法
用法2: 函数指针数组
int (*pFunc[2])(int,int)
#include <iostream>
using namespace std;
int add(int a,int b){
return a+b;
}
int reduce(int a, int b){
return a-b;
}
int test(int a,int b, int (*pFunc)(int ,int )){
return (*pFunc)(a,b);
}
int main(int argc, char const *argv[])
{
int a=3,b=4;
/***************函数指针数组**********************/
int (*pf[2])(int,int);
pf[0]=add;
pf[1]=reduce;
for (int i=0; i<2; i++) {
cout<<pf[i](a,b)<<endl;
}
return 0;
}
run
7
-1