What is the value of ~0 in C?

后端 未结 7 1499
暖寄归人
暖寄归人 2021-01-02 10:22

I want to get the values of INT_MIN and INT_MAX. I\'ve tried ~0 and ~0 >> 1 since the leftmost bit is a sign bit bu

7条回答
  •  遥遥无期
    2021-01-02 10:40

    ~0 is -1. Every C implementation that you're likely to run into uses two's complement for signed integers, so 0xffffffff is -1 (assuming 32-bit integers). ~0 >> 1 is the equivalent of dividing -1 by 2; since we're doing integer arithmetic, the result is -1.

提交回复
热议问题