Can the type difference between constants 32768 and 0x8000 make a difference?

后端 未结 5 1923
攒了一身酷
攒了一身酷 2021-01-04 04:30

The Standard specifies that hexadecimal constants like 0x8000 (larger than fits in a signed integer) are unsigned (just like octal constants), whereas decimal constants like

5条回答
  •  春和景丽
    2021-01-04 05:05

    On a 32 bit platform with 64 bit long, a and b in the following code will have different values:

    int x = 2;
    long a = x * 0x80000000; /* multiplication done in unsigned -> 0           */
    long b = x * 2147483648; /* multiplication done in long     -> 0x100000000 */
    

提交回复
热议问题