C++ Literals
| Type |
Base |
Example |
Description |
| char * |
ASCII |
"hello" |
Any string of characters enclosed in double quotes (") (see
Note 1) |
| char |
ASCII |
'1' |
One character in single quotes (') |
| unsigned short int |
ASCII |
L'ab' |
One or two characters in single quotes ('), preceded by the
letter L |
| int |
octal |
01 |
Any octal number (digits 0-7) beginning with a 0 (zero) |
| decimal |
1 |
Any decimal number (digits 0-9) not beginning with a 0
(zero) |
| hexadecimal |
0x1 |
0X (zero X) or 0x (zero x) followed by any hexadecimal number
(digits 0-F) |
| ASCII |
'ABC' |
Two to four characters in single quotes (') |
| unsigned int |
octal |
01U |
Any octal number (digits 0-7) beginning with a 0 (zero) and
followed by U or u |
| decimal |
1U |
Any decimal number (digits 0-9) not beginning with a 0 (zero)
and followed by U or u |
| hexadecimal |
0x1U |
0X (zero X) or 0x (zero x) followed by any hexadecimal number
(digits 0-F) and followed by U or u |
| long int |
octal |
01L |
Any octal number (digits 0-7) beginning with a 0 (zero) and
followed by L or l |
| decimal |
1L |
Any decimal number (digits 0-9) not beginning with a 0 (zero)
and followed by L or l |
| hexadecimal |
0x1L |
0X (zero X) or 0x (zero x) followed by any hexadecimal number
(digits 0-F) and followed by L or l |
| unsigned long int |
octal |
01UL |
Any octal number (digits 0-7) beginning with a 0 (zero) and
followed by U or u and L or l |
| decimal |
1UL |
Any decimal number (digits 0-9) not beginning with a 0 (zero)
and followed by U or u and L or l |
| hexadecimal |
0x1UL |
0X (zero X) or 0x (zero x) followed by any hexadecimal number
(digits 0-F) and followed by U or u and L or l |
| float |
decimal |
12.3F |
Any number (digits 0-9) containing a decimal point (.) and
followed by F or f |
| decimal |
12E1F |
Any number (digits 0-9) followed by E or e, followed by an
exponent of 10 (12E1 = 12 * 101 = 120.), and followed by F or
f |
| double |
decimal |
12.3 |
Any number (digits 0-9) containing a decimal point (.) |
| decimal |
12E1 |
Any number (digits 0-9) followed by E or e and followed by an
exponent of 10 (12E1 = 12 * 101 = 120.) |
| long double |
decimal |
12.3L |
Any number (digits 0-9) containing a decimal point (.) and
followed by L or l |
| decimal |
12E1L |
Any number (digits 0-9) followed by E or e, followed by an
exponent of 10 (12E1 = 12 * 101 = 120.), and followed by L or
l |
Notes:
- String constants are stored as the literal characters followed
by a byte of binary 0. The value returned is a pointer to the
first character.
|