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).

 

arrow
arrow
    文章標籤
    programming
    全站熱搜
    創作者介紹
    創作者 紅線 的頭像
    紅線

    紅線的生存日誌

    紅線 發表在 痞客邦 留言(0) 人氣()