函数指针:
#include<stdio.h>
int add(int a
,int b
)
{
return a
+ b
;
}
int max(int a
, int b
)
{
return a
> b
? a
: b
;
}
int main(void)
{
int(*p
)(int, int);
int status
= 0;
printf("请输入你要计算的函数1:max;2:add");
scanf_s("%d",&status
);
if (status
== 1)
p
= max
;
else
{
p
= add
;
}
int i
= 0;
i
= p(5, 7);
printf("i = %d\n",i
);
system("pause");
return 0;
}
根据输入的状态进行判断,到底调用的是哪一个
转载请注明原文地址:https://blackberry.8miu.com/read-3365.html