What are arithmetic underflow and overflow in C?

前端 未结 4 1572
深忆病人
深忆病人 2020-12-05 07:57

What do arithmetic underflow and overflow mean in C programming?

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 08:17

    Computers use only 0 and 1 to represent data so that the range of values that can be represented is limited. Many computers use 32 bits to store integers, so the largest unsigned integer that can be stored in this case is 2^32 -1 = 4294967295. But the first bit is used to represent the sign, so, in fact, the largest value is 2^31 - 1 = 2147483647.

    The situation where an integer outside the allowed range requires more bits than can be stored is called an overflow.

    Similarly, with real numbers, an exponent that is too small to be stored causes an underflow.

提交回复
热议问题