Calculating Ranges of Data Types in C

前端 未结 5 2099
眼角桃花
眼角桃花 2020-12-05 22:02

I\'m working through K&R Second Edition, and can\'t figure out why I\'m getting a certain result. The problem I\'m solving is calculating upper and lower limits for data

5条回答
  •  Happy的楠姐
    2020-12-05 22:39

    You may be interested in constant in limits.h and float.h header files

    From limits.h:

    +------------+------------------------------------------------------------------+--------------------------------+
    | CHAR_BIT   | Number of bits in a char object (byte)                           | 8 or greater                   |
    | SCHAR_MIN  | Minimum value for an object of type signed char                  | -127 (-2^7+1) or less          |
    | SCHAR_MAX  | Maximum value for an object of type signed char                  | 127 (2^7-1) or greater         |
    | UCHAR_MAX  | Maximum value for an object of type unsigned char                | 255 (2^8-1) or greater         |
    | CHAR_MIN   | Minimum value for an object of type char                         | either SCHAR_MIN or 0          |
    | CHAR_MAX   | Maximum value for an object of type char                         | either SCHAR_MAX or UCHAR_MAX  |
    | MB_LEN_MAX | Maximum number of bytes in a multibyte character, for any locale | 1 or greater                   |
    | SHRT_MIN   | Minimum value for an object of type short int                    | -32767 (-2^15+1) or less       |
    | SHRT_MAX   | Maximum value for an object of type short int                    | 32767 (2^15-1) or greater      |
    | USHRT_MAX  | Maximum value for an object of type unsigned short int           | 65535 (2^16-1) or greater      |
    | INT_MIN    | Minimum value for an object of type int                          | -32767 (-2^15+1) or less       |
    | INT_MAX    | Maximum value for an object of type int                          | 32767 (2^15-1) or greater      |
    | UINT_MAX   | Maximum value for an object of type unsigned int                 | 65535 (2^16-1) or greater      |
    | LONG_MIN   | Minimum value for an object of type long int                     | -2147483647 (-2^31+1) or less  |
    | LONG_MAX   | Maximum value for an object of type long int                     | 2147483647 (2^31-1) or greater |
    | ULONG_MAX  | Maximum value for an object of type unsigned long int            | 4294967295 (2^32-1) or greater |
    +------------+------------------------------------------------------------------+--------------------------------+
    

提交回复
热议问题