C 整數常數
「整數常數」為代表整數值的十進位 (底數為 10)、八進位 (底數為 8) 或十六進位 (底數為 16) 數字。 使用整數常數來表示無法變更的整數值。
語法
integer-constant
:
decimal-constant
integer-suffix
opt
octal-constant
integer-suffix
opt
hexadecimal-constant
integer-suffix
opt
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
opt
unsigned-suffix
long-long-suffix
unsigned-suffix
64-bit-integer-suffix
long-suffix
unsigned-suffix
opt
long-long-suffix
unsigned-suffix
opt
64-bit-integer-suffix
unsigned-suffix
:下列其中一個
u U
long-suffix
:下列其中一個
l L
long-long-suffix
:下列其中一個
ll LL
64-bit-integer-suffix
:下列其中一個
i64 I64
i64
和 I64
尾碼是 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;