C 整数常量C Integer Constants

“整数常量”是表示整数值的十进制(基数为 10)、八进制(基数为 8)或十六进制(基数为 16)数字。An "integer constant" is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents an integral value. 使用整数常量表示不能更改的整数值。Use integer constants to represent integer values that cannot be changed.

语法Syntax

integer-constant:integer-constant:
decimal-constant integer-suffix optdecimal-constant integer-suffix opt

octal-constant integer-suffix optoctal-constant integer-suffix opt

hexadecimal-constant integer-suffix opthexadecimal-constant integer-suffix opt

decimal-constant:decimal-constant:
nonzero-digitnonzero-digit

decimal-constant digitdecimal-constant digit

octal-constant:octal-constant:
00

octal-constant octal-digitoctal-constant octal-digit

hexadecimal-constant:hexadecimal-constant:
0x hexadecimal-digit0x hexadecimal-digit

0X hexadecimal-digit0X hexadecimal-digit

hexadecimal-constant hexadecimal-digithexadecimal-constant hexadecimal-digit

nonzero-digit: one ofnonzero-digit: one of
1 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 9

octal-digit: one ofoctal-digit: one of
0 1 2 3 4 5 6 70 1 2 3 4 5 6 7

hexadecimal-digit: one ofhexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 90 1 2 3 4 5 6 7 8 9

a b c d e fa b c d e f

A B C D E FA B C D E F

integer-suffix:integer-suffix:
unsigned-suffix long-suffix optunsigned-suffix long-suffix opt

long-suffix unsigned-suffix optlong-suffix unsigned-suffix opt

unsigned-suffix: one ofunsigned-suffix: one of
u Uu U

long-suffix: one oflong-suffix: one of
l Ll L

64-bit integer-suffix:64-bit integer-suffix:
i64i64

整数常量为正数,除非它们的前面有减号 (-)。Integer constants are positive unless they are preceded by a minus sign (-). 减号解释为一元算术求反运算符。The minus sign is interpreted as the unary arithmetic negation operator. (有关此运算符的信息,请参阅一元算术运算符。)(See Unary Arithmetic Operators for information about this operator.)

如果整数常量以 0x0X 开始,则它是十六进制。If an integer constant begins with 0x or 0X, it is hexadecimal. 如果它以数字 0 开始,则为八进制。If it begins with the digit 0, it is octal. 否则,将其假定为十进制。Otherwise, it is assumed to be decimal.

下列行是等效的:The following lines are equivalent:

0x1C   /* = Hexadecimal representation for decimal 28 */  
034    /* = Octal representation for decimal 28 */  

空白字符不能分隔整数常量的数字。No white-space characters can separate the digits of an integer constant. 这些示例显示有效的十进制、八进制和十六进制常量。These examples show valid decimal, octal, and hexadecimal constants.

/* Decimal Constants */  
10  
132  
32179  

/* Octal Constants */  
012  
0204  
076663  

/* Hexadecimal Constants */  
0xa or 0xA  
0x84  
0x7dB3 or 0X7DB3  

另请参阅See Also

C 常量C Constants