An escape sequence in C language is a sequence of characters that doesn’t represent itself when used inside string literal or character.
Generally, an escape sequence begins with a backslash ‘\’ followed by a character or characters.
It is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.
It is composed of two or more characters starting with backslash \. For example: \n represents new line.
Escape sequences are used to format the output text and are not generally displayed on the screen.
List of Escape Sequences in C
Escape Sequence | Meaning |
---|---|
\a | Alarm or Beep |
\b | Backspace |
\f | Form Feed |
\n | New Line |
\r | Carriage Return |
\t | Tab (Horizontal) |
\v | Vertical Tab |
\\ | Backslash |
\’ | Single Quote |
\” | Double Quote |
\? | Question Mark |
\nnn | octal number |
\xhh | hexadecimal number |
\0 | Null |
Example
#include<stdio.h>
int main(){
int number=50;
printf("You\nare\nlearning\n\'c\' language\n\"Do you know C language\"");
return 0;
}
Example – 2
#include <stdio.h>
int main ()
{
printf("\n horizontal tab escape sequence tutorial");
printf(" \n 34543 \t 345435 ");
printf(" \n 123 \t 678 ");
return 0;
}