#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/