c - 关于C函数

标签 c

#include<stdio.h>

int add(int x,int y,int z){
    return x+z+y;
}
int main(){
    float w = printf("%d\n", add(40, 40, 55));
    printf("%f",w);
    return 0;
}

谁能解释一下“w”的值为 4 吗?

最佳答案

来自printf

Return value

Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).

在您的示例中,您的 printf 打印 135 和 '\n' ,从而给出 4

尝试不同的变化并查看

float w=printf("%d\n",add(40,40,55));
printf("%f\n",w);

 w=printf("%d\n",add(40,0,5));
printf("%f\n",w);

 w=printf("%d\n",add(0,0,5));
printf("%f\n",w);
<小时/>

完全不同的注释 w 应该是 int

关于c - 关于C函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52914403/

相关文章:

c - C 函数中的函数

c - 为什么 scanf 不遵循带有非空白字符的文档?

c - 实现回溯 N 皇后算法

c - 如何阅读 GUID 分区表 (GPT) 及其条目?

c - arm-none-eabi-ld : section . ARM.exidx 与 .data 部分重叠

c++ - 如何创建自定义字节级数据类型?

c - malloc 之后是否必须初始化 char* ?

c++ - 显示任何类型的一维或二维数组内容的函数

c - 关于用两个七段灯显示0x00到0xFF的问题

c - 为什么我在 C++ (C++14) 中使用指针初始化数组时出错?