Data Type Truncation

后端 未结 2 1596
小蘑菇
小蘑菇 2021-01-27 11:42

I have a basic C question.

Suppose I\'ve declared and initialized a standard 16 bit unsigned integer

uint16_t var1 = 0x1234;

and then s

2条回答
  •  再見小時候
    2021-01-27 12:36

    I think you mean:

    uint16_t var1 = 0x1234;
    uint8_t var2;
    var2 = var1;
    

    Yes, this will truncate var1 to fit within var1's data type, so var2 will be equal to 0x34.

提交回复
热议问题