Escape Sequence in C

Escape Sequence or Escape characters are special characters start with backslash (\) in C Language. Escape sequences are combination of two or more characters within a string to represent a special action.

Popular Escape Sequence in C Language.

\n    To change the line.
\t For Tabbed space between two characters or string.

Example 1: Both printf() statement will print in same line.

#include<stdio.h>
int main()
{
	printf("Coder");
	printf("Mantra");
	return 0;
}
Output : CoderMantra

Example 2: Both printf() statement will print in different line because of \n.

#include<stdio.h>
int main()
{
	printf("Coder");
	printf("\nMantra");
	return 0;
}
Output : Coder
Mantra

Example 3: Tabbed space (Tab key on keyboard) between two word because of \t.

#include<stdio.h>
int main()
{
	printf("Coder");
	printf("\tMantra");
	return 0;
}
Output : Coder    Mantra

Example 4: Another Example of \n and \t.

#include<stdio.h>
int main()
{
	printf("________________\n");
	printf("|\t\t|\n");
	printf("|\tHello  \t|\n");
	printf("|\t\t|\n");
	printf("----------------\n");
	return 0;
}
Output :
________________
| |
| Hello |
| |
----------------

List of Important Escape Sequences in C Programming.

\n    To change the line
\t For Tabbed space between two character or string.
\b Backspace.
\r Carriage return (moves the cursor in the begining of line).
\ To print backslash ().
\" To print Quotation mark.
\' To print single inverted comma.

Mini Quiz

0%

C Programming - Quiz 2

1 / 5

Q1. What is the purpose of an escape sequence in C?

2 / 5

Q2. Which escape sequence is used to move the cursor to the next line?

3 / 5

Q3. Which escape sequence is used to insert a tab space between two words?

4 / 5

Q4. Which escape sequence is used for a backspace operation?

5 / 5

Q5. Which escape sequence moves the cursor to the beginning of the current line?

Your score is

The average score is 0%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top