如果我写
unsigned long long x = ....
unsigned short y = ...
if(x == y) ....
长的长会变成短的吗?或者空头会被转换为多头吗?我假设较短的数据类型将被转换为较长的数据类型以防止截断/数据丢失。
最佳答案
将级别较低的整型对象转换为级别较高的对象的整型。在您的情况下,无符号短将隐式转换为无符号长长。就是所谓的‘普通算术转换’。
根据C++标准
If both operands are of arithmetic or enumeration type, the usual arithmetic conversions are performed on both operands;
关于c++ - 当比较短和长时,哪个会被转换到哪个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22649440/