C++

Escape Sequences in C/C++2 min read

Escape sequences are used in the programming languages C and C++, and their design was copied in many other languages such as Java and C#. Escape sequences are the special characters used in control string to modify the format of the output. These characters are not displayed in output. These characters are used with combination of backslash \. This backslash \ is called escape character.

Table of Escape sequence of C & C++ are as follows:

Escape SequencesPurpose
\aAlarm (Beep, bell)
\ttab
\nnew line
\fForm Feed
\rCarriage Return
\’Single quote mark
\”Double quote mark
\?Question mark
\bBackspace




\a
This escape sequence is used to play beep dueing program’s execution.
For example:

Output:


After displaying “Code” the computer will beep and then print “Example.

 

\t
This escape sequence is used to insert tab in text.
For example:

Output:


First “Code” will printed on screen then \t inserts a TAB and then “Fellow” is printed so at the end we will get output: Code Example.

 

\n
This escape sequence is used to insert newline in text.
For example:

Output:


First “Code” will printed on screen then \n inserts a new line and then “Example” is printed so at the end we will get output: Code
Example.

 

\r
This escape sequence is used to insert carriage return in text.
For example:

Output:


First “Code” will printed on screen then \r move the cursor at begining of screen and then Fellow will be print.

 

\’
This escape sequence is used to print single quote mark ‘ in text.
For example:

Output:


First “Code” will printed on screen then \’ print ‘ and then “Example” is printed so at the end we will get output: Code’Example.

 

\”
This escape sequence is used to print double quote marks ” in text.
For example:

Output:


First “Code” will printed on screen then \” inserts double quote mark and then “Example” is printed so at the end we will get output: Code”Example.

 

\b
This escape sequence is used to delete previous character.
For example:

Output:


First “Code” will printed on screen then \b delete previous character and then “Example” is printed so at the end we will get output: CodExample.

 

 

 

Leave a Comment