Size of int and float

后端 未结 6 740
夕颜
夕颜 2021-02-01 07:17

I have a question about the ranges of ints and floats:

If they both have the same size of 4 bytes, why do they have different ranges?

6条回答
  •  鱼传尺愫
    2021-02-01 07:31

    Two types with the same size in bytes can have different ranges for sure.

    For example, signed int and unsigned int are both 4 bytes, but one has one of its 32 bits reserved for the sign, which lowers the maximum value by a factor of 2 by default. Also, the range is different because the one can be negative. Floats on the other hand lose value range in favor of using some bits for decimal range.

提交回复
热议问题