C++ Crash Course: a fast-Paced Introduction


Chapter 2 Unicode Escape Characters



Yüklə 7 Mb.
Pdf görüntüsü
səhifə69/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

38
Chapter 2
Unicode Escape Characters
You can specify Unicode character literals using the universal character names
and you can form a universal character name in one of two ways: the prefix 
\u
followed by a 4-digit Unicode code point or the prefix 
\U
followed by an 
8-digit Unicode code point. For example, you can represent the 
A
character 
as 
'\u0041'
and represent the beer mug character 
🍺
as 
U'\U0001F37A'
.
Format Specifiers
The 
printf
format specifier for 
char
is 
%c
. The 
wchar_t
format specifier is 
%lc
.
Listing 2-4 initializes two character literals
x
and 
y
. You use these vari-
ables to build a 
printf
call.
#include
int main() {
char x = 'M';
wchar_t y = L'Z';
printf("Windows binaries start with %c%lc.\n", x, y);
}
Windows binaries start with MZ.
Listing 2-4: A program that assigns several character-typed variables and prints them
This program outputs Windows binaries start with MZ. Even though the 
M is a narrow character 
char
and the Z is a wide character, 
printf
works 
because the program uses the correct format specifiers.
N O T E
 
The first two bytes of all Windows binaries are the characters M and Z, an homage to 
Mark Zbikowski, the designer of the MS-DOS executable binary file format.
Boolean Types
Boolean types have two states: true and false. The sole Boolean type is 
bool

Integer types and the 
bool
types convert readily: the 
true
state converts to 
1, and 
false
converts to 0. Any non-zero integer converts to true, and 0 con-
verts to 
false
.

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