Characters such as backspace or control characters have no visible image and they are nonprintable. Other characters (like single or double quotation marks question marks and backslash) have special meanings in the programming language and you cannot use any of these characters directly. Instead, you need to use an escape sequence to represent such characters.
An Escape Sequence begins with backslash (\) followed by a character or by a combination of digits.
There are several escape sequences are defined in C++ programming language such as:
Escape Sequence | Character Represented |
---|---|
\n | New Line |
\t | Horizontal Tab |
\b | Backspace |
\" | Double quote |
\' | Single quote |
\? | Question Mark |
\r | Carriage Return |
\a | Alert (bell) |
\\ | Backslash |
\f | Form feed (new page) |
//Example of C++ Escape Sequence #include<iostream> using namespace std; int main() { cout<<"This is an example of \'single quotes\' and \"double quotes\""; cout<<"\nThis is an example of newline and \\backslash"; cout<<"\nThis is an example of \t Horizontal tab and a\bbackspace"; return 0; }
This is an example of 'single quotes' and "double quotes" This is an example of newline and \backslash This is an example of Horizontal tab and backspace
No comments:
Post a Comment