C usual arithmetic conversions

前端 未结 4 928
攒了一身酷
攒了一身酷 2020-12-01 15:08

I was reading in the C99 standard about the usual arithmetic conversions.

If both operands have the same type, then no further conversion is needed.

4条回答
  •  Happy的楠姐
    2020-12-01 16:02

    Indeed b is converted to unsigned. However what you observed is that b converted to unsigned and then added to 10 gives as value 5.

    On x86 32bit this is what happens

    1. b, coverted to unsigned, becomes 4294967291 (i.e. 2**32 - 5)
    2. adding 10 becomes 5 because of wrap-around at 2**32 (2**32 - 5 + 10 = 2**32 + 5 = 5)

提交回复
热议问题