Why is there one more negative int than positive int?

后端 未结 3 1745
独厮守ぢ
独厮守ぢ 2021-01-12 07:28

The upper limit for any int data type (excluding tinyint), is always one less than the absolute value of the lower limit.

For example, the

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 08:04

    Let's say you have a 4byte (32 bit) integer. The range defined by C++ is -231 to 231-1. So we end up with a range -231.....0......231. We can think of this as having 231 non negative integers (note 0 is included) and 231 negative integers.

提交回复
热议问题