【发布时间】:2012-07-01 22:19:27
【问题描述】:
我不明白为什么程序控制没有到达第三个 printf,就在 for 循环之后。
为什么不打印第三个printf?
如果我将 for 循环更改为 while 循环,它仍然不会打印。
这是程序和输出:
main()
{
double nc;
printf ("Why does this work, nc = %f\n", nc);
for (nc = 0; getchar() != EOF; ++nc)
{
printf ("%.0f\n", nc);
}
printf ("Why does this work, nc = %f", nc);
}
输出是:
Why does this work, nc = 0.000000
test
0
1
2
3
4
【问题讨论】:
-
尝试在最后一个 printf 中添加换行符。
-
这可能会回答你的问题:stackoverflow.com/a/1716621/748875
-
出于兴趣:为什么
double用于 nc?int肯定会更传统吗?
标签: c for-loop terminal while-loop printf