Menu Close

Escape Sequences in C

Posted in C Programming

An escape sequence is a combination of characters that represents a special character, which cannot be represented directly in a string or character literal.

In C programming language, there are 256 numbers of characters in character set. The entire character set is divided into 2 parts i.e. the ASCII characters set and the extended ASCII characters set. But apart from that, some other characters are also there which are not the part of any characters set, known as ESCAPE characters.

Escape sequences are used to represent special characters in strings or characters, such as the newline character (\n), the tab character (\t), the backslash character (), and the null character (\0), among others. These characters are considered special because they cannot be typed directly on the keyboard or represented in a character or string literal.

Escape sequences are represented by a backslash () followed by a character or a combination of characters. For example, the escape sequence for the newline character is \n, and the escape sequence for the tab character is \t.

Escape sequences are widely used in C programming language to format output, print special characters, and manipulate strings and characters in various ways.

here’s a table with some of the commonly used escape sequences in C:

Escape Sequence Description
\n newline character
\t tab character
\r carriage return character
\b backspace character
\f form feed character
\v vertical tab character
single quote character
double quote character
\ backslash character
\0 null character

Note that the escape sequence for each special character is represented by a backslash (\) followed by a specific character or combination of characters.

Related:   Literals in C Programming

We will learn more about escape sequence in printf() function chapter.

Leave a Reply