Character
Effect **: ** character variable for displaying a single character
Syntax **: ** char ch = 'a';
> Note 1: When displaying character variables, single quote character enclosed, not in double quotes
> Note 2: single quotes only one character , not a string
. 1 #include <the iostream>
2 the using namespace STD;
. 3
. 4 int main () {
. 5 // . 1, create a character variable manner
. 6 char CH = ' A ' ;
. 7 COUT CH << << endl;
. 8
. 9 // 2 , character variable memory size occupied
10 COUT << " char string variables share the memory: " << the sizeof ( char ) << endl;
. 11
12 is // . 3, character variable common error
13 is // char = CH2 " b "; being given double quotes, use single quotes
14 // char CH2 = 'ABCD'; When creating a variable character, a single character can have only one quote
15
16 // 4, corresponding to the ASCII code character variable
. 17 // A --97
18 is // A --65
. 19 << COUT ( int ) CH << endl;
20 is System ( " PAUSE " );
21 is
22 is return 0 ;
23 is }
ASCII code roughly grouped into the following ** ** two:
* ASCII non-printing control characters: Digital ** ** 0-31 on the ASCII table assigned to the control characters, used to control a number of peripheral devices such as printers.
* ASCII printing characters: 32-126 ** ** Digital assigned to a character can be found on the keyboard, when viewed or printed document will appear.
Escape character
** Role: ** == used to represent the number of ASCII characters can not be displayed ==
At present, we have a common escape characters: \ n \\ \ t
1 int main() { 2 //转义字符 3 4 //换行符 \n 5 cout << "Hello world\n"; 6 //反斜杠 \\ 7 8 cout << "\\"<< endl; 9 //水平制表符 \t 作用可以整齐输出数据 10 11 cout << "aaa\thelloworld" << endl; 12 cout << "aa\thelloworld" << endl; 13 cout << "aaaaa\thelloworld" << endl; 14 system("pause"); 15 16 return 0; 17 }