1 #include2 3 int sum(int a, int b) 4 { 5 return a+b; 6 } 7 8 int minus(int a, int b) 9 {10 return a-b;11 }12 13 int x(int a, int b)14 {15 return a*b;16 }
//第一个参数为指向函数的指针,返回类型为int,参数是int,int
1 void counting(int (*p)(int, int), int a, int b) 2 { 3 int result = p(a, b); 4 printf("result = %d\n", result); 5 } 6 7 int main() 8 { 9 //指向函数的指针10 counting(sum, 1, 2);//counting(minus, 1, 2); counting(x, 1, 2);11 return 0;12 }