这里是一个非常简单的C语言程序:
int main()
{
int i = 0;
while(i++ < 10)
printf("%d\n", i);
return 0;
}
结果为:
1
2
3
4
5
6
7
8
9
10
为什么打印的第一个数字不是0
?
如果我将i++
替换为++i
,会得到以下结果:
1
2
3
4
5
6
7
8
9
对于 i++
和 ++i
, 第一个数都是 1
。
我在 while()
循环中期望看到后增量的 0
。
谢谢。
i
之后打印它,那么您怎么能看到0
呢?! - StoryTeller - Unslander Monicawhile(i++ < 10) /*i is incremented here*/ printf("%d\n", i);
- HolyBlackCat