下面的C代码给出了输出"hello5“...how?
#include<stdio.h>
int main(){
int f = fun();
printf("%d",f);
return 0;
}
void fun(){
printf("hello");
}发布于 2015-03-20 14:12:18
您看到的是未定义的行为。
值f永远不会被初始化,而您打印的是未初始化的变量,这将导致未定义的行为。
printf()返回成功打印的字符数,因此这里的计数是5( hello ),用于打印hello。
如果需要,您需要返回此值,因为您在main()中初始化了变量f,因此您已经定义了行为。
int func()
{
int j;
j = printf("hello");
return j;
}https://stackoverflow.com/questions/29160419
复制相似问题