编程错误,指向函数的指针
#include<stdio.h>int main(void){ int max(int,int); int min(int,int); int add(int,int); void process(int x,int y,int(*p)()); int a,b; printf("input a b:"); scanf("%d%d",&a,&b); printf("%d",max); process(a,b,max); printf("%d",min); process(a,b,min); printf("%d",add); process(a,b,add); return 0;}int max(int x,int y){ if(x>y) return x; else return y;}int min(int x,int y){ if(x>y) return y; else return x;}int add(int x,int y){ return x-y;}︶ㄣ痕迹の天涯 发表于 2014-3-15 00:00 static/image/common/back.gif
#include
int main(void)
{
int main()
{
int Max(int,int);
int Min(int,int);
int add(int,int);
int process(int x,int y,int(*p)(int,int));
int a,b;
printf("input a b:\n");
scanf("%d%d",&a,&b);
printf("Max:%d\n",process(a,b,Max));
printf("Min:%d\n",process(a,b,Min));
printf("Add:%d\n",process(a,b,add));;
return 0;
}
int Max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int Min(int x,int y)
{
if(x>y)
return y;
else
return x;
}
int add(int x,int y)
{
return x+y;
}
int process(int x,int y,int(*p)(int,int))
{
return p(x,y);
}
猜了你大概的想法 给你改了一下 #include<stdio.h>
int main(void)
{
int max(int,int);
int min(int,int);
int add(int,int);
void process(int x,int y,int(*p)());
int a,b;
printf("input a b:");
scanf("%d%d",&a,&b);
printf("%d",max);
process(a,b,max);
printf("%d",min);
process(a,b,min);
printf("%d",add);
process(a,b,add);
return 0;
}
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int min(int x,int y)
{
if(x>y)
return y;
else
return x;
}
int add(int x,int y)
{
return x-y;
}
抱歉啊,上面格式错了 machimilk 发表于 2014-3-15 00:27 static/image/common/back.gif
int main()
{
int Max(int,int);
#include<stdio.h>
int main(void)
{
int max(int,int);
int min(int,int);
int add(int,int);
void process(int x,int y,int(*p)(int,int));
int a,b;
printf("input a b:");
scanf("%d%d",&a,&b);
printf("%d\n",max);
process(a,b,max);
printf("%d\n",min);
process(a,b,min);
printf("%d\n",add);
process(a,b,add);
return 0;
}
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int min(int x,int y)
{
if(x>y)
return y;
else
return x;
}
int add(int x,int y)
{
return x+y;
}
void process(int x,int y,int(*p)(int,int))
{
;
}
这返回的好像是地址啊, 3楼正解,void process(int x,int y,int(*p)());这个函数声明了,却没有定义,更没有调用. 其实我想说 写成这样有意思么#include<stdio.h>
int max(int x,int y);
void process(int * t (int,int),int x,int y);
int main()
{
int x,y;
printf("please input two number:");
scanf("%d%d",&x,&y);
process(max,x,y);
return 0;
}
int max(int x,int y)
{
if(x>y)
{
return x;
}
else
{
return y;
}
}
void process(int * t (int,int),int x, int y)
{
printf("max = %d\n",t(x,y));
} 同上。。。。。 #include<stdio.h>
int max(int x,int y) {
if(x>y)
return x;
else
return y;
}
int min(int x,int y) {
if(x>y)
return y;
else
return x;
}
int add(int x,int y) {
return x+y;
}
int process(int (*p) (int, int), int x,int y) {
return (*p) (x, y);
}
void main(){
int a,b, result1, result2, result3;
printf("input a b:");
scanf("%d%d",&a,&b);
result1=process(max, a, b);
printf("%d\n",result1);
result2=process(min, a, b);
printf("%d\n",result2);
result3=process(add, a, b);
printf("%d\n",result3);
}
︶ㄣ痕迹の天涯 发表于 2014-3-15 12:00 static/image/common/back.gif
#include
int main(void)
{
函数的指针难道不是函数的地址吗
页:
[1]