找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 166|回复: 0

函数指针的相关用法

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-10-27 19:52:01 | 显示全部楼层 |阅读模式
函数指针:void (*f) ()
函数返回指针:void *f ()
const指针:const int*
指向const的指针:int *const
指向const的const的指针:const int * const

找出下面程序的错误:
int max(int x, int y)
{
   return x > y?x:y;
}
int main()
{
int max(x, y);//应该改为int max(int, int);
int *p = &max;//应该改为int (*p)(int, int) = &max;这里注意函数指针的定义和初始化方式。
int a, b, c, d;
printf("please input three integer\n");
scanf("%d%d%d", a,b,c);//应该改为scanf("%d%d%d", &a, &b, &c);
d = (*p)((*p)(a, b), c);
printf("Among %d, %d, and %d, the maxmal integer is %d\n", a, b, c, d);
return 0;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 15:14 , Processed in 0.102954 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表