Signed int range confusion

后端 未结 5 860
终归单人心
终归单人心 2021-01-29 09:10

This question might be very basic but i post here only after days of googling and for my proper basic understanding of signed integers in C.

Actually some say signed int

5条回答
  •  悲&欢浪女
    2021-01-29 09:30

    It depends on your environment and typically int can store -2147483648 to 2147483647 if it is 32-bit long and two's complement is used, but C specification says that int can store at least -32767 to 32767.

    Quote from N1256 5.2.4.2.1 Sizes of integer types

    Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

    — minimum value for an object of type int
    INT_MIN -32767 // −(2 15 − 1)
    — maximum value for an object of type int
    INT_MAX +32767 // 2 15 − 1`

提交回复
热议问题