Home » Escape Sequences In C++

Escape Sequences In C++1 min read

by TechABU
Escape Sequence C++ with examples

Some characters in C++ have unique meanings. These characters are escape sequences that perform some special function, and they begin with a “\” (Backslash is called escape character) followed by a letter or number. The output doesn’t display these characters.

Difference Types of Escape Sequence In C++

In C++, there are several escape sequences. The following are the most regularly used escape sequences in C++:


The \n escape sequence character is used in C++ to insert a new line in the output.

For example:
cout << “Learn With\nTechABU” ;

Learn With


The \t escape sequence character is used in C++ to insert a TAB in output.

For example:
cout << “Learn With\tTechABU” ;

Learn With		TechABU


The \a is an escape sequence used in C++ to generate a signal to alert (alarm).

cout<< “Welcome To The \a Future” ;

In the above line of code, the compiler will first print “Welcome To The” and then alert a signal, and then it will print “Future.”

List of All Escape Sequences Used In C++

Alert\aMakes an alarm sound, such as a beep.
Backspace\bBackspaces the cursor one space.
Formfeed\fMoves the cursor to next logical page.
Newline\nMoves the cursor to the next line.
Carriage Return\rMoves cursor to the beginning of the line.
Horizontal Tab\tInserts a Horizontal Tab
Vertical Tab\vInserts a Vertical Tab
Single Quote\'Prints a Single Quote.
Double Quote\"Prints a Double Quote.
Backslash\\Prints a backslash
Question Mark\?Prints a question mark.
Octal/Hex Number\numberConvert to a char that is represented by an octal/hex number.

Example Program For Escape Sequence

// \t Escape Sequence Program Example

using namespace std;
int main()

	cout<< " I'm learning... \t C++ Programming ";
	return 0;
I'm learning...        C++ Programming

Leave a Comment


Send this to a friend