代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
(i + x) = 2
Set x to -6
(i + x) = 4294967295
Run Code Online (Sandbox Code Playgroud)
在这个例子中,(i + x) 返回的结果类型是一个无符号整数,但是,我认为通过算术类型转换,应该“提升”有符号整数(在这种情况下为变量“x”)在操作发生之前转换为无符号整数。这一定不是这种情况,因为 (i + x) 的第一个结果是 (5 …