|
|
发表于 2018-5-15 09:46:48
|
显示全部楼层
本帖最后由 风过无痕丶 于 2018-5-15 09:53 编辑
你是不是对函数指针有什么误解
- #include<stdio.h>
- // 函数声明
- int max(int a, int b);
- int min(int a, int b);
- int add(int a, int b);
- int main()
- { // 这里是声明函数指针!
- int(*process)(int x, int y);
- int a, b;
- printf("Please enter a and b:");
- scanf("%d %d", &a, &b);
- printf("\n");
- // 这里是给函数指针赋值!
- process = max;
- printf("Max = %d\n", process(a, b));
- process = min;
- printf("Min = %d\n", process(a, b));
- process = add;
- printf("Add = %d\n", process(a, b));
- return 0;
- }
- int max(int x, int y) {
- return x > y ? x : y;
- }
- int min(int x, int y) {
- return x < y ? x : y;
- }
- int add(int x, int y)
- {
- int add;
- add = x + y;
- return add;
- }
复制代码 |
|