这个c++程序运行为什么会得到-32768

来源:百度知道 编辑:UC知道 时间:2024/06/17 02:31:55
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{ // max value if shorts are 8 bits
short short_value = 32767;
short ival = 1;
// this calculation overflows
short_value += ival;
cout << "short_value: " << short_value << endl;

return 0;
}

short
2
short int, signed short int
–32,768 to 32,767

越界了大哥

最大的0xffff
+1
溢出:

这个问题真是无聊,书本上明明写行很清楚.

你的程序也写得很清楚,好心你学学英文吧.// this calculation overflows