#include <stdio.h>
int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int max(int,int);
int (*p)(int,int)=&max;
int a,b,c,d;
printf("Please input three integer \n");
scanf("%d %d %d",&a,&b,&c);
d=(*p)((*p)(a,b),c);
printf("Among %d,%d,%d ,the max integer is %d \n",a,b,c,d);
return 0;
}
/*函数指针,即指向函数的指针
void (*f)();
函数返回指针,即指针函数
void *f();
*/函数指针的使用
本文通过一个C语言程序示例介绍了如何使用函数指针来实现最大值的比较。程序定义了一个max函数用于比较两个整数并返回较大值,并通过函数指针调用该函数实现了三个整数中最大值的确定。

被折叠的 条评论
为什么被折叠?



