Signed int range confusion

后端 未结 5 855
终归单人心
终归单人心 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:44

    My doubt is what is the actual range of signed int in c ,1) [-32767 to 32767] or 2) [-32768 to 32767]?

    The whole point of C and its advantage of high portability to old and new platforms is that code should not care.

    C defines the range of int with 2 macros: INT_MIN and INT_MAX. The C spec specifies:
    INT_MIN is -32,767 or less.
    INT_MAX is +32,767 or more.

    If code needs a 16-bit 2's complement type, use int16_t. If code needs a 32-bit or wider type, use long or int32least_t, etc. Do not code assuming int is something that it is not defined to be.

提交回复
热议问题