Escape Sequence in C Language
An escape sequence in C language is a sequence of characters that denotes a different meaning from its actual meaning and undergoes a change from its normal form when used inside string literal or character. It is composed of two or more characters starting with backslash \.
List of Escape Sequences in C
| Escape Sequence | Meaning |
|---|---|
| \a | Alarm or Beep |
| \b | Backspace |
| \e | Used For Escape Characters |
| \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 |
| \N | Octal Constant |
| \xhh | Hexadecimal Number |
| \XN | Hexadecimal Constant |
| \0 | Null |
#include<stdio.h>
void main()
{
printf("\nLearn Easy Tutorial For Escape Sequences!\n\n");
printf("Print a new\nline!\n");// newline!
printf("\'Hello World\'!\n"); // single quotation!
printf("20\v30\n"); // vertical tab!
printf("\"Escape Sequences!\"\n"); // double quotation!
printf("Hello!");
printf("\r"); // carriage return!
printf("An example!\n");
printf("What are you doing\?\n"); // question mark!
printf("E:\\LearnEasy\\LearnC\n"); // backslash!
char* oct = "B\142"; // Octal Value!
printf("%s\n", oct); // Print Octal Value!
char* hexval = "B\x2L"; // Hexadecimal Value
printf("%s\n", hexval); // Print Hexadecimal Value!
}
Output :
Learn Easy Tutorial For Escape Sequences!
Print a new
line!
'Hello World'!
20
30
"Escape Sequences!"
An example!
What are you doing?
E:\LearnEasy\LearnC
Bb
BL
ADVERTISEMENT
