C++ 整数限制C++ Integer Limits

Microsoft 专用Microsoft Specific

下表列出了整数类型的限制。The limits for integer types are listed in the following table. 这些限制在标准标头文件 LIMITS.H 中定义。These limits are defined in the standard header file LIMITS.H. Microsoft C 还允许声明固定大小的整数变量,即大小为 8 位、16 位、或 32 位的整数类型。Microsoft C also permits the declaration of sized integer variables, which are integral types of size 8-, 16-, or 32-bits. 有关固定大小整数的详细信息,请参阅固定大小整数类型For more information on sized integers, see Sized Integer Types.

对整数常量的限制Limits on Integer Constants

常量Constant 含义Meaning Value
CHAR_BITCHAR_BIT 不是位域的最小变量中的位数。Number of bits in the smallest variable that is not a bit field. 88
SCHAR_MINSCHAR_MIN signed char 类型的变量的最小值。Minimum value for a variable of type signed char. -128-128
SCHAR_MAXSCHAR_MAX signed char 类型的变量的最大值。Maximum value for a variable of type signed char. 127127
UCHAR_MAXUCHAR_MAX unsigned char 类型的变量的最大值。Maximum value for a variable of type unsigned char. 255 (0xff)255 (0xff)
CHAR_MINCHAR_MIN char 类型的变量的最小值。Minimum value for a variable of type char. -128;如果使用了 /J 选项,则为 0-128; 0 if /J option used
CHAR_MAXCHAR_MAX char 类型的变量的最大值。Maximum value for a variable of type char. 127;如果使用了 /J 选项,则为 255127; 255 if /J option used
MB_LEN_MAXMB_LEN_MAX 多字符常量中的最大字节数。Maximum number of bytes in a multicharacter constant. 55
SHRT_MINSHRT_MIN short 类型的变量的最小值。Minimum value for a variable of type short. -32768-32768
SHRT_MAXSHRT_MAX short 类型的变量的最大值。Maximum value for a variable of type short. 3276732767
USHRT_MAXUSHRT_MAX unsigned short 类型的变量的最大值。Maximum value for a variable of type unsigned short. 65535 (0xffff)65535 (0xffff)
INT_MININT_MIN int 类型的变量的最小值。Minimum value for a variable of type int. -2147483647 - 1-2147483647 - 1
INT_MAXINT_MAX int 类型的变量的最大值。Maximum value for a variable of type int. 21474836472147483647
UINT_MAXUINT_MAX unsigned int 类型的变量的最大值。Maximum value for a variable of type unsigned int. 4294967295 (0xffffffff)4294967295 (0xffffffff)
LONG_MINLONG_MIN long 类型的变量的最小值。Minimum value for a variable of type long. -2147483647 - 1-2147483647 - 1
LONG_MAXLONG_MAX long 类型的变量的最大值。Maximum value for a variable of type long. 21474836472147483647
ULONG_MAXULONG_MAX unsigned long 类型的变量的最大值。Maximum value for a variable of type unsigned long. 4294967295 (0xffffffff)4294967295 (0xffffffff)

如果值超出了最大整数表示形式,则 Microsoft 编译器会产生错误。If a value exceeds the largest integer representation, the Microsoft compiler generates an error.

结束 Microsoft 专用END Microsoft Specific

另请参阅See Also

C 整数常量C Integer Constants