C 整数常量

整数常量是一个十进制(base 10)、八进制(base 8)或十六进制(base 16)数字,表示整数值。 使用整数常量表示无法更改的整数值。

语法

integer-constant:
decimal-constant integer-suffix 选择
octal-constant integer-suffix 选择
hexadecimal-constant integer-suffix 选择

decimal-constant:
nonzero-digit
decimal-constant digit

octal-constant:
0
octal-constant octal-digit

hexadecimal-constant:
hexadecimal-prefix hexadecimal-digit
hexadecimal-constant hexadecimal-digit

hexadecimal-prefix:其中一个
0x 0X

nonzero-digit:其中一个
1 2 3 4 5 6 7 8 9

octal-digit:其中一个
0 1 2 3 4 5 6 7

hexadecimal-digit:其中一个
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F

integer-suffix:
unsigned-suffix long-suffix 选择
unsigned-suffix long-long-suffix
unsigned-suffix 64-bit-integer-suffix
long-suffix unsigned-suffix 选择
long-long-suffix unsigned-suffix 选择
64-bit-integer-suffix

unsigned-suffix:其中一个
u U

long-suffix:其中一个
l L

long-long-suffix:其中一个
ll LL

64-bit-integer-suffix:其中一个
i64 I64

i64I64缀Microsoft特定。

整数常量是正的,除非它们前面有减号(-)。 减号被解释为一元算术求反运算符。 (有关此运算符的信息,请参阅 一元算术运算符

如果整数常量以或0X十六进制开头0x。 如果以数字 0开头,则为八进制。 否则,它假定为十进制。

以下整数常量是等效的:

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

空格字符不能分隔整数常量的数字。 这些示例显示了一些有效的十进制、八进制和十六进制常量。

    /* Decimal Constants */
    int                 dec_int    = 28;
    unsigned            dec_uint   = 4000000024u;
    long                dec_long   = 2000000022l;
    unsigned long       dec_ulong  = 4000000000ul;
    long long           dec_llong  = 9000000000LL;
    unsigned long long  dec_ullong = 900000000001ull;
    __int64             dec_i64    = 9000000000002I64;
    unsigned __int64    dec_ui64   = 90000000000004ui64;

    /* Octal Constants */
    int                 oct_int    = 024;
    unsigned            oct_uint   = 04000000024u;
    long                oct_long   = 02000000022l;
    unsigned long       oct_ulong  = 04000000000UL;
    long long           oct_llong  = 044000000000000ll;
    unsigned long long  oct_ullong = 044400000000000001Ull;
    __int64             oct_i64    = 04444000000000000002i64;
    unsigned __int64    oct_ui64   = 04444000000000000004uI64;

    /* Hexadecimal Constants */
    int                 hex_int    = 0x2a;
    unsigned            hex_uint   = 0XA0000024u;
    long                hex_long   = 0x20000022l;
    unsigned long       hex_ulong  = 0XA0000021uL;
    long long           hex_llong  = 0x8a000000000000ll;
    unsigned long long  hex_ullong = 0x8A40000000000010uLL;
    __int64             hex_i64    = 0x4a44000000000020I64;
    unsigned __int64    hex_ui64   = 0x8a44000000000040Ui64;

另请参阅

C 常量