我来我网
https://5come5.cn
 
您尚未 登录  注册 | 菠菜 | 软件站 | 音乐站 | 邮箱1 | 邮箱2 | 风格选择 | 更多 » 
 

本页主题: 出现问题老,c编译错误 显示签名 | 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

瓜瓜坠地





性别: 帅哥 状态: 该用户目前不在线
等级: 栋梁之材
家族: 考研俱乐部
发贴: 594
威望: 0
浮云: 1161
在线等级:
注册时间: 2006-05-12
最后登陆: 2007-01-09

5come5帮你背单词 [ aspect /'æspekt/ n. 样子,面貌,(问题、事物等的)方面 ]


出现问题老,c编译错误

#include <stdio.h>
#include <stdlib.h>

int get_result(int a, int b, int (*compare)())
{
  return(compare(a, b)); // Invoke the function passed
}


int max(int a, int b)
{
  printf("In max\n");
  return((a > b) ? a: b);
}

int min(int a, int b)
{
  printf("In min\n");
  return((a < b) ? a: b);
}

int main(void)
{
  int result;

  result = get_result(1, 2, &max);
  printf("Max of 1 and 2 is %d\n", result);
 
  result = get_result(1, 2, &min);
  printf("Min of 1 and 2 is %d\n", result);
  system("pause");
 return 0;
}
  就是这个程序,不知道有什么问题
顶端 Posted: 2006-09-27 10:43 | [楼 主]
一夜N阵风



贴图大师奖
性别: 帅哥 状态: 该用户目前不在线
头衔: *&*牛仔*&*
等级: 荣誉会员
家族: 梦魇图腾
发贴: 38652
威望: 4
浮云: 833
在线等级:
注册时间: 2005-03-14
最后登陆: 2008-03-07

5come5帮你背单词 [ asleep /ə'sli:p/ a. 睡着的,睡熟的 ]


int get_result(int a, int b, int (*compare)())
{
return(compare(a, b)); // Invoke the function passed/*此处应改为return((*compare)(a, b)); */
}
result = get_result(1, 2, &max);/*改为result = get_result(1, 2, max);*/
result = get_result(1, 2, &min);/*改为result = get_result(1, 2, min);*/
lz没搞清楚函数指针,函数名中存储的就是函数的入口地址,如:定义int (*p)(int ,int);
和int max(int a,int b),可直接赋值p=max,引用时要(*p)(a,b)
顶端 Posted: 2006-09-27 17:53 | [1 楼]
我来我网·5come5 Forum » 程序员之家

Total 0.010349(s) query 6, Time now is:01-25 01:08, Gzip enabled
Powered by PHPWind v5.3, Localized by 5come5 Tech Team, 黔ICP备16009856号