Escape Sequence in C++ and their Uses with Examples

In this article, we will discuss about Escape Sequence and their uses in C++ language with Examples and outputs.

Escape Sequence

Escape sequences are special non-printing characters used to control the printing behaviour of output stream objects (eg “cout”).

The compiler doesn’t show all these characters in the output.

Escape Character

Backslash (/) is called as an escape character.

Following are important escape sequences of C++ and we will further discuss them.

\n  = newline

\r = carriage return

\t  = tab

\” = double quote

\? = question

\\ = backslash

\’ = single quote

\n (Newline)

\n is used to print the code on a new line.

Use of \n

It inserts a new line and the cursor moves to the beginning of the next line.

Example of \n

In this example when we add /n in the cout the new line starts and other output is moved to next line.

\r Carriage Return

\r is used for return.

a carriage return is a type of escape character that will reset the position of the cursor to the beginning of a line of text

Example of Carriage Return

\t Tab

\t is used to insert tab space horizontally in the output of the code.

It usually gives the space of in word.


\” Double Quote

\” Backslash double quote is used to display ” ” quotes in the output


\’ Single Quote

\’ Backslash Single Quote is used to display ‘ ‘ Single quote in the output.


\? Question

\? Backslash Question Mark is used to displaying the question mark in the output.


\\ Backslash

\\ Backslash Backslash is used to display the backslash in the output.


Leave a Reply

Featured Posts

FSc 2nd year English Notes Complete of All Chapters


FSc 2nd year Computer Science Chapter 10 Notes


FSc 2nd year Math Chapter 5 Notes – Linear Inequalities and Linear Programming


FSc 2nd year Math Chapter 7 Notes – Vectors

my hobby quotes

My Hobby Essay with Quotations – English Essay


FSc 2nd year Computer Science Chapter 5 Notes