Some escape sequences and usage of it in a C program.
List of the escape sequence
| Escape Sequence | Usage |
| \a | Alarm or Beep |
| \b | Backspace |
| \f | Formfeed |
| \n | New Line |
| \r | Carriage Return |
| \t | Tab (Horizontal) |
| \v | Vertical Tab |
| \\ | Backslash |
| \' | Single Quote |
| \" | Double Quote |
| \? | Question Mark |
| \ooo | Octal Number |
| \xhh | Hexadecimal Number |
| \0 | Null |
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Demonstrating use of \\n \\t \\r and \\b\n\n");
printf("Use of \\n: \\n is used to add a new line.\n");
printf("line1.\nline2.\n\n");
printf("Use of \\t: \\t is used to add the horizontal tab.\n");
printf("word1\tword2\n\n");
printf("Use of \\r: \\r is used to bring the cursor to the beginning of the line.\n");
printf("olleH World!\rHello\n\n");
printf("Use of \\b: \\b is used to bring the cursor one step back.\n");
printf("Hello World!\b#");
getch();
}
Output:
Demonstrating use of \n \t \r and \b
Use of \n: \n is used to add a new line.
line1.
line2.
Use of \t: \t is used to add the horizontal tab.
word1 word2
Use of \r: \r is used to bring the cursor to the beginning of the line.
Hello World!
Use of \b: \b is used to bring the cursor one step back.
Hello World#
Comments
Post a Comment