int max = ~0; What does it mean?

前端 未结 8 2099
灰色年华
灰色年华 2021-01-19 03:46

int max = ~0;

What does it mean?

8条回答
  •  清歌不尽
    2021-01-19 04:37

    ~ means bitwise not, it inverts all the bits in the given integer. In a signed int this will give you -1 (since all the bits in the int will be flipped from 0 to 1.) Look up two's complement for more information on this one.

    In an unsigned int (uint) this would give you the maximum value of an integer (since the most significant bit in an unsigned int doesn't determine the sign.)

提交回复
热议问题