【发布时间】:2016-04-28 20:21:10
【问题描述】:
这两个程序有什么区别?第一个程序的输出为 9,第二个程序的输出为 10。
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; // Don't forget to declare variables
while ( x < 10 ) { // While x is less than 10
cout << x << endl;
x++; // Update x so the condition can be met eventually
}
cin.get();
}
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; // Don't forget to declare variables
while ( x < 10 ) { // While x is less than 10
x++; // Update x so the condition can be met eventually
cout << x << endl;
}
cin.get();
}
【问题讨论】:
-
第 10 行和第 11 行互换。
-
@Fozi 哈哈哈,可爱的回答
-
同样,
001110101和jkfbvafdsf是 codeS,但int main(void) {}是 code。 -
使用调试器单步执行并观察 x 的值
-
@SuperKhew:我没有看到 Fozi 评论中的幽默。这就是答案。
标签: c++