When an int is cast to a short and truncated, how is the new value determined?

后端 未结 6 466
借酒劲吻你
借酒劲吻你 2020-12-01 13:53

Can someone clarify what happens when an integer is cast to a short in C? I\'m using Raspberry Pi, so I\'m aware that an int is 32 bits, and theref

6条回答
  •  借酒劲吻你
    2020-12-01 14:13

    Simply the high 16 bits are cut off from the integer. Therefore your short will become 0x8642 which is actually negative number -31166.

提交回复
热议问题