printf()中的c函数调用错误

标签 c

#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;
}

这个程序无法运行。我认为代码是正确的。你能指出错误吗?

最佳答案

adder是一个函数,你应该printf是它的返回值。

正如 @JonathanLeffler 所说,如果您想确保输出及时出现,最好在末尾添加换行符。所以,

改变

adder( a,b);
printf("sum is %d",adder);

至:

int result = adder(a,b);
printf("sum is %d\n", result);

或发送至:

printf("sum is %d\n", adder(a, b));

关于printf()中的c函数调用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23259236/

相关文章:

c - C-透明regex.h使用教程

c - C 中的 %f 和 %F 有什么区别?

c - 使用 mbed 框架在 STM32 上运行 GMP 的串行 printf

c - 在 Linux 中获取自 1984 年 1 月 1 日午夜以来的绝对时间

c - 在C中使用fread读取文件

C指针查询

c - 如何在openCV的全屏无边框窗口中显示图像

为 SWIG 创建类型映射,以便 C 函数可以返回 Lua 表

C: 用 scanf fork

c - 如何正确使用循环和堆栈来模拟递归?