Review of char type,one-dimensional char arrays,string,common problem types. The organization of knowledge points is somewhat rough, but they are all key points that must be mastered. The knowledge points regarding string positions are quite detailed, and this area can test loops, arrays, and characters, making it a comprehensive topic. Therefore, strings are often tested in various competitions, not only focusing on these basic concepts but also assessing students’ overall problem-solving abilities.1. Review of char type
| Definition |
char c; // stores a single character, where a single letter, number, or other symbol enclosed in single quotes counts as a single character Line breaks, tabs, and spaces also count as single characters that can be stored in a char type variable |
| Direct assignment |
char a=’-‘; Note: it is single quotes! |
| Input a single character |
1. cin>>a; cin ignores line breaks, spaces, tabs, and other whitespace characters by default 2. scanf(“%c”,&a); scanf can also handle the input of a single whitespace character 3. How to read line breaks, spaces, tabs, and other whitespace characters? a=getchar(); reads a character from the keyboard and assigns it to a |
| Output a single character |
cout<<a; printf(“%c”,a); |
| Essence of character storage | All characters correspond to a unique number called the ASCII code to remember:
97->’a’ 65->’A’ 48->’0′ Lowercase letters – 32 = uppercase letters Uppercase letters + 32 = lowercase letters |
2. One-dimensional char arrays, two-dimensional
The usage can be compared to one-dimensional and two-dimensional arrays.
| Definition |
char c[10]; |
| Direct assignment |
char a[10]={‘y’,’u’,’a’,’n’}; Note: unassigned positions are automatically assigned ‘ |