In the character set, one type of character has this feature: When this character is entered from the keyboard, the character can be displayed on the display, that is, what the input displays. This type of character is known as a display character, such as A, B, C, $, +, and spaces.
Another type of character has no such feature. They may not find a key on the keyboard (which can be entered in a special way, of course), or the characters on the key face cannot be displayed after the key. In fact, such characters are designed for control purposes, so called control characters.
In C, the control characters that make up the constants of a character must be represented by an escape character. An escape character is a character that begins with "\". For example, backspace uses ' \b ' to indicate that the line break is ' \ n '. The ' \ ' in the escape character means that the character behind it has lost its original meaning and has changed to another specific meaning. A backslash forms a specific character along with the character that follows it.
An escape character is a special form of a character that is represented in the C language. The escape character begins with the backslash ' \ ' followed by a character or a octal or hexadecimal number. The escape character has a specific meaning, which is different from the original meaning of the character, so it is called the escape character.
An escape character is typically used to denote a character that is not printable in the ASCII character set, such as a single apostrophe (') used to represent the constants quantity of a character, a double apostrophe (") and a backslash (\), and so on, for a string constant.
Example Explanation:
You can output strings through puts, for example:
The ASCII value of "123ABC" corresponds to the octal of 61, 62, 63, 141, 142, 143, and the above code can also be written as:
Puts ("\61\62\63\141\142\143");
In C, all ASCII codes can be represented by a backslash, plus number (default is 8), called the escape character (escape Character) because \ behind
Character is not the same as the original ASCII character.
In addition to octal, you can also use hexadecimal notation. In hexadecimal, the number begins with an X. The hexadecimal value of the "123ABC" corresponding to the ASCII code is 31,
32, 33, 61, 62, 63, so can also be written as:
Puts ("\x31\x32\x33\x61\x62\x63");
Note: You can only use octal or hexadecimal, and you cannot use decimal.
A complete example:
#include <stdio.h>
int main () {
puts ("The string is: \61\62\63\x61\x62\x63");
return 0;
}
Run Result:
The string is:123abc
In ASCII code, the characters from 0~31 (decimal) are control characters, they are invisible characters, they cannot be displayed on the monitor, they cannot be written, they can only be turned
To represent the form of a literal character. However, the direct use of ASCII code value memory is inconvenient, for commonly used control characters, C language also defines a shorthand, complete the list is as follows:
Escape character |
Significance |
ASCII code value (decimal) |
\a |
Bell (BEL) |
007 |
\b |
BACKSPACE (BS) to move the current position to the previous column |
008 |
\f |
Change page (FF) to move the current position to the beginning of the next page |
012 |
\ n |
Line Break (LF), move the current position to the beginning of the next line |
010 |
\ r |
Enter (CR) to move the current position to the beginning of the bank |
013 |
\ t |
Horizontal tab (HT) (jumps to the next tab position) |
009 |
\v |
Vertical tabulation (VT) |
011 |
Escape Character Descriptor Example:
#include <stdio.h>
int main () {
puts ("C\tc++\tjava\nc-appeared!\a");
return 0;
}
Run Result:
C + + Java
C-appeared!
At the same time will hear the speaker "beep" sound, this is the use of \a effect.
The above is the C language of the escape character data collation, learning C language students can see.