Information Technology Reference
In-Depth Information
Character Literals
A character literal consists of a character representation between two single quote characters.
A character representation can be any of the following: a single character, a simple escape
sequence, a hex escape sequence, or a Unicode escape sequence.
The type of a character literal is char .
￿
￿A simple escape sequence is a backslash followed by a single character.
￿
A hex escape sequence is a backslash, followed by an upper or lowercase x , followed by
up to four hex digits.
￿
A Unicode escape sequence is a backslash, followed by an upper or lowercase u , fol-
lowed by up to four hex digits.
For example, the following code shows various formats of character literals:
char c1 = 'd'; // Single character
char c2 = '\n'; // Simple escape sequence
char c3 = '\x0061'; // Hex escape sequence
char c4 = '\u005a'; // Unicode escape sequence
Some of the important special characters and their encodings are shown in Table 8-3.
Table 8-3. Important Special Characters
Name
Escape Sequence
Hex Encoding
\0
Null
0x0000
Alert
\a
0x0007
\b
Backspace
0x0008
Horizontal tab
\t
0x0009
\n
New line
0x000A
Vertical tab
\b
0x000B
\f
Form feed
0x000C
Carriage return
\r
0x000D
\"
Double quote
0x0022
Single quote
\'
0x0027
\\
Backslash
0x005C
Search WWH ::




Custom Search