[英]c function calling error in printf()
#include<stdio.h>
#include<conio.h>
int adder(int,int);
void main()
{
int a,b;
printf("enter nos");
scanf("%d%d",&a,&b);
adder( a,b);
printf("sum is %d",adder);
getch();
}
int adder(int x,int y)
{
return x+y;
}
this program is not working.I think the code is right.Can you point out the error?这个程序不工作。我认为代码是对的。你能指出错误吗?
adder
is a function, what you should printf
is its return value. adder
是一个函数,你应该printf
是它的返回值。
And as @JonathanLeffler said, it's better to add a newline at the end if you want to ensure the output appears timely.正如@JonathanLeffler 所说,如果您想确保输出及时出现,最好在末尾添加换行符。 So,所以,
change改变
adder( a,b);
printf("sum is %d",adder);
to:到:
int result = adder(a,b);
printf("sum is %d\n", result);
or to:或者:
printf("sum is %d\n", adder(a, b));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.