c语言中0x1是什么,0x1L在c語言中是什么意思

本文详细介绍了C++中的整型常量,包括十进制、八进制和十六进制的表示方式,以及如何指定无符号和长整型类型。通过前缀和后缀来指定基数和类型,例如使用0开始的数字表示八进制,0x或0X开头的表示十六进制,后缀u或U表示无符号,l或L表示长整型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#4

C++ Integer Constants

Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.

Syntax

integer-constant :

decimal-constant integer-suffixopt

octal-constant integer-suffixopt

hexadecimal-constant integer-suffixopt

'c-char-sequence'

decimal-constant :

nonzero-digit

decimal-constant digit

octal-constant :

0

octal-constant octal-digit

hexadecimal-constant :

0x hexadecimal-digit

0X hexadecimal-digit

hexadecimal-constant hexadecimal-digit

nonzero-digit : one of

1 2 3 4 5 6 7 8 9

octal-digit : one of

0 1 2 3 4 5 6 7

hexadecimal-digit : one of

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-suffixopt

long-suffix unsigned-suffixopt

unsigned-suffix : one of

u U

long-suffix : one of

l L

64-bit integer-suffix :

i64

To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.

To specify a decimal constant, begin the specification with a nonzero digit. For example:

int i = 157;   // Decimal constant

int j = 0198;  // Not a decimal number; erroneous octal constant

int k = 0365;  // Leading zero specifies octal constant, not decimal

To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:

int i = 0377;   // Octal constant

int j = 0397;   // Error: 9 is not an octal digit

To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:

int i = 0x3fff;   // Hexadecimal constant

int j = 0X3FFF;   // Equal to i

To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:

unsigned uVal = 328u;             // Unsigned value

long lVal = 0x7FFFFFL;            // Long value specified

//  as hex constant

unsigned long ulVal = 0776745ul;  // Unsigned long value

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值