close
#include <iostream>
int main(int argc, char **argv)
{
std::cout << 25u - 50;
return 0;
}
其結果是 4294967271, 即 2^32-1-24
原因是25 unsigned number -50 結果也是一個unsigned number
-25的unsigned number 即為 2^32-1-24。
In C++, if the types of two operands differ from one another, then the operand with the “lower type” will be promoted to the type of the “higher type” operand, using the following type hierarchy (listed here from highest type to lowest type): long double, double, float, unsigned long int, long int, unsigned int, int (lowest).
文章標籤
全站熱搜