以下代码在调试模式和发布模式下生成不同的结果(使用Visual Studio 2008):
int _tmain(int argc, _TCHAR* argv[])
{
for( int i = 0; i < 17; i++ )
{
int result = i * 16;
if( result > 255 )
{
result = 255;
}
printf("i:%2d, result = %3d\n", i, result) ;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调试模式的输出,如预期的那样:
i: 0, result = 0
i: 1, result = 16
(...)
i:14, result = 224
i:15, result = 240
i:16, result = 255
Run Code Online (Sandbox Code Playgroud)
释放模式的输出,其中i:15结果不正确:
i: 0, result = 0
i: 1, result …
Run Code Online (Sandbox Code Playgroud)