C comparison char and int

前端 未结 6 1149
走了就别回头了
走了就别回头了 2020-12-06 03:13

In the code block below what\'s the impicit conversion that takes place in the if statement for 7? I would have though it would end up being (0x98 <= 0x07) but that\'s no

6条回答
  •  难免孤独
    2020-12-06 04:11

    What's likely happening here is that char is a signed value and 0x98 is hence registering as a negative number. Hence it is less than 7

    Also in this scenario, 7 will under go no conversion. Instead the char will be widened to the same integral type as 7 and then a comparison will be done.

提交回复
热议问题