Escape Sequences for Nonprintable Characters in C++

By: Stanley B. Viewed: 1396 times  Printer Friendly Format    

Some characters are nonprintable. A nonprintable character is a character for which there is no visible image, such as backspace or a control character. Other characters have special meaning in the language, such as the single and double quotation marks, and the backslash. Nonprintable characters and special characters are written using an escape sequence. An escape sequence begins with a backslash. The language defines the following escape sequences:




horizontal tab


vertical tab




carriage return




alert (bell)




question mark


single quote


double quote



We can write any character as a generalized escape sequence of the form


where ooo represents a sequence of as many as three octal digits. The value of the octal digits represents the numerical value of the character. The following examples are representations of literal constants using the ASCII character set:

     \7 (bell)      \12 (newline)     \40 (blank)
     \0 (null)      \062 ('2')        \115 ('M')

The character represented by '\0' is often called a "null character," and has special significance, as we shall soon see.

We can also write a character using a hexadecimal escape sequence


consisting of a backslash, an x, and one or more hexadecimal digits.

Most Viewed Articles (in C++ )

Latest Articles (in C++)

Comment on this tutorial