签名转换为无符号
带符号整型可以将对象转换为相应的无符号类型。 当这些转换发生时,实际位组合不更改;但是,数据的解释更改。 考虑此代码:
示例
// conve__pluslang_Converting_Signed_to_Unsigned.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
int main()
{
short i = -3;
unsigned short u;
cout << (u = i) << "\n";
}
Output
65533
在前面的示例中, signed short, i,定义和初始化为负数。 该表达式 (u = i) 导致 i 转换为 unsigned short 在该赋值之前对 u。