整型Integer Types

根据每个整数常量的值及其表示方式为该常量提供一个类型。Every integer constant is given a type based on its value and the way it is expressed. 可通过将字母 lL 追加到任何整数常量的末尾来将该常量强制转换为类型 long;可通过将 uU 追加到该值来将其强制转换为类型 unsignedYou can force any integer constant to type long by appending the letter l or L to the end of the constant; you can force it to be type unsigned by appending u or U to the value. 小写字母 l 会与数字 1 发生混淆,应避免此情况出现。The lowercase letter l can be confused with the digit 1 and should be avoided. 某些形式的 long 整数常量如下所示:Some forms of long integer constants follow:

/* Long decimal constants */  
10L  
79L  

/* Long octal constants */  
012L  
0115L  

/* Long hexadecimal constants */  
0xaL or 0xAL  
0X4fL or 0x4FL  

/* Unsigned long decimal constant */  
776745UL  
778866LU  

您分配给常量的类型取决于常量表示的值。The type you assign to a constant depends on the value the constant represents. 常量的值必须在其类型的可表示值的范围内。A constant's value must be in the range of representable values for its type. 常量的类型用于确定在表达式中使用常量或在应用减号 (-) 时执行的转换类型。A constant's type determines which conversions are performed when the constant is used in an expression or when the minus sign (-) is applied. 此列表汇总了整数常量的转换规则。This list summarizes the conversion rules for integer constants.

  • 不带后缀的十进制常量的类型是 intlong intunsigned long int。可用来表示常量值的三种类型中的第一个类型是分配给常量的类型。The type for a decimal constant without a suffix is either int, long int, or unsigned long int. The first of these three types in which the constant's value can be represented is the type assigned to the constant.

  • 分配给不带后缀的八进制和十六进制常量的类型是 intunsigned intlong intunsigned long int,具体取决于常量的大小。The type assigned to octal and hexadecimal constants without suffixes is int, unsigned int, long int, or unsigned long int depending on the size of the constant.

  • 分配给带 uU 后缀的常量的类型是 unsigned intunsigned long int,具体取决于常量的大小。The type assigned to constants with a u or U suffix is unsigned int or unsigned long int depending on their size.

  • 分配给带 lL 后缀的常量的类型是 long intunsigned long int,具体取决于常量的大小。The type assigned to constants with an l or L suffix is long int or unsigned long int depending on their size.

  • 分配给带 uU 后缀的常量和带 lL 后缀的常量的类型是 unsigned long intThe type assigned to constants with a u or U and an l or L suffix is unsigned long int.

另请参阅See Also

C 整数常量C Integer Constants