C++ Crash Course: a fast-Paced Introduction



Yüklə 7 Mb.
Pdf görüntüsü
səhifə68/71
tarix20.09.2023
ölçüsü7 Mb.
#145939
1   ...   63   64   65   66   67   68   69   70   71
C Crash Course A Fast-Paced Introduction by Josh Lospinoso

Character Types
Character types store human language data. The six character types are:
char
 
The default type, always 1 byte. May or may not be signed. 
(Example: ASCII.)


Types
37
char16_t
Used for 2-byte character sets. (Example: UTF-16.)
char32_t
Used for 4-byte character sets. (Example: UTF-32.)
signed char
Same as 
char
but guaranteed to be signed.
unsigned char
Same as 
char
but guaranteed to be unsigned.
wchar_t
Large enough to contain the largest character of the imple-
mentation’s locale. (Example: Unicode.)
The character types 
char

signed char
, and 
unsigned char
are called narrow 
characters, whereas 
char16_t

char32_t
, and 
wchar_t
are called wide characters due 
to their relative storage requirements.
Character Literals
character literal is a single, constant character. Single quotation marks (
' '

surround all characters. If the character is any type but 
char
, you must also 
provide a prefix: 
L
for 
wchar_t

u
for 
char16_t
, and 
U
for 
char32_t
. For example, 
'J'
declares a 
char
literal and 
L'J'
declares a 
wchar_t
.
Escape Sequences
Some characters don’t display on the screen. Instead, they force the display 
to do things like move the cursor to the left side of the screen (carriage 
return) or move the cursor down one line (newline). Other characters can 
display onscreen, but they’re part of the C++ language syntax, such as single 
or double quotes, so you must use them very carefully. To put these charac-
ters into a 
char
, you use the escape sequences, as listed in Table 2-3.
Table 2-3: 
Reserved Characters and Their Escape Sequences
Value
Escape sequence
Newline
\n
Tab (horizontal)
\t
Tab (vertical)
\v
Backspace
\b
Carriage return
\r
Form feed
\f
Alert
\a
Backslash
\\
Question mark
?
or 
\?
Single quote
\'
Double quote
\"
The null character
\0



Yüklə 7 Mb.

Dostları ilə paylaş:
1   ...   63   64   65   66   67   68   69   70   71




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin