0
#include<iostream>
using std::cout; using std::endl;
int main()
{
unsigned int i = 5;
int x = -3;
cout << "(i + x) = " << (i + x) << endl;
cout << "Set x to -6" << endl;
x = -6;
cout << "(i + x) = " << (i + x) << endl;
}
输出:
(i + x) = 2
Set x to -6
(i + x) = 4294967295
在该示例中,结果的类型由返回第(i + x)的是一个无符号整数,但是,我认为在算术类型转换时,在操作发生之前,有符号整数(在这种情况下是变量“x”)应该被“提升”为无符号整数。由于(i + x)的第一个结果是(5 +(2^31 - 1 - 3))= 4294967297而不是2,所以一定不是这种情况。有没有我在这里失踪的东西?在我看来,只有最终结果被转换为无符号整数,而不是最初的操作数。
无符号数字[wrap modulo](http://stackoverflow.com/a/22801135/1708801) –