Integer Literals
decimal; octal; hexadecimal
- begin with
0
(zero) are interpreted as octal - begin with either
0x
or0X
are interpreted as hexadecimal
int k;
scanf("%x", &k); // cin >> F
printf("%d", k); // cout << 15
[! Attention]
The value of a decimal literal is never a negative number. The minus sign is not part of the literal. ==The minus sign is an 🔗^4ded86 that negates the value== of its (literal) operand.
By default, decimal literals are signed
whereas octal and hexadecimal literals can be either signed or unsigned types.There are no literals of type short
Floating-point Literals
either a decimal point or an exponent specified using scientific notation.
Attention
By default, floating-point literals have type double. We can override the default using a suffix. ==So,
double
is preferable.==
Character and Character String Literals
The type of a string literal is array of constant chars.
在 C/C++ 中,“”
会被解释为以 \0
结束,吗?
Boolean and Pointer Literals
The words true and false are literals of type bool
The word nullptr is a pointer literal.
Escape Sequences
\x
followed by one or more hexadecimal digits\
followed by one, two, or three octal digits- Note that if a
\
is followed by more than three octal digits, only the first three are associated with the\
.
- Note that if a
Specifying the Type of a Literal
using some letters as prefix or suffix. (C++ Primer, p.40, Table2.2)