非常简单的代码(在MS Visual C++ 2008 Express下):
#include <iostream>
using namespace std;
int main()
{
for (int a=1; 2*a<=7; a++)
cout << a << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调试模式给出了正确的结果:
1
2
3
Run Code Online (Sandbox Code Playgroud)
但是发布模式给了我错误的结果:
1
2
Run Code Online (Sandbox Code Playgroud)
好吧,我理解可能的答案"使用2*a <8"; "为什么不<= 3","a <4".
我不想更改代码,因为它是正确的代码(在调试模式下运行良好,所有变量都初始化良好,等等).
更新:
我写的时候
cout << a+1 << endl;
Run Code Online (Sandbox Code Playgroud)
要么
cout << 2*a << endl;
Run Code Online (Sandbox Code Playgroud)
它工作/编译正确(3行输出).
注意: 我尝试使用VC++ 2008 Express在不同的计算机上运行.同样的行为.