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

后端 未结 6 459
借酒劲吻你
借酒劲吻你 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:31

    The 32 bit value is truncated to 16 bits in the same way a 32cm long banana bread would be cut if you jam it into a 16cm long pan. Half of it would fit in and still be a banana bread, and the rest will be "gone".

提交回复
热议问题