When we use output function like printf() than Escape Sequences helps in formatting the output. All Escapse Sequences start from '\' (forward slash)
S.No. | Escape Sequence | Description | Example |
---|---|---|---|
\a | Alert or Beep | printf("Hello User\a"); | |
\b | Backspace | printf("Hello\b\b\b User"); He User | |
\n | New line | printf("Hello\nUser"); Hello User | |
\r | Carriage Return | use in file handling | |
\t | Tab (Horizontal) | printf("Hello\tUser"); Hello User | |
\? | Question Mark | printf("How are you\?"); How are you? | |
\' | Single Quote | printf("How\'s that"); How's that | |
\" | Double Quote | printf("\"C\" - Language"); "C" - Language | |
\\ | Backslash | printf("File is in c:\\abc"); File is in c:\abc |
Example 1: Escape Sequence 1
#include<stdio.h>
void main()
{
printf("You\nare\nlearning\n\'c\' - \"language\"");
}
Example 2: Escape Sequence 1
#include<stdio.h>
void main()
{
printf("A\nB\n"); //new line
printf("A\tB\n"); //tab
printf("\'ABC\'\n"); //single quotes
printf("\"ABC\"\n"); //double quotes
printf("\nHow are you\?"); //Question Mark
printf("\nFile path is c:\\new folder\\file.ext");
}