Sometimes, it is required to use newline, tab, quotation mark etc. in the program which either cannot be typed or has special meaning in C programming. In such cases, escape sequence are used. For that incident \n is used for newline. The backslash “\” causes escape from the standard way the characters are interpreted by the compiler.
This escape sequences are only used in printing statements like printf for example:
printf(“\n Hello \t World!”).
Table of Escape Sequences:
Escape | Character |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Return |
\t | Horizontal tab |
\v | Vertical tab |
\\ | Backslash |
\’ | Single quotation mark |
\* | Double quotation mark |
\? | Question mark |
\0 | Null character |
Examples created on escape sequence:
#include <stdio.h> void main(){ printf (“\nHello\nWorld!”); } | #include<stdio.h> void main ( ){ Comment printf (“Hello\tWorld!”); } | #include<stdio.h> void main(){ printf(“Hello World” \n); } |
o/p: Hello World | O/p: Hello World! | O/p: Error Note: Sequence escape always in between “ double quote” |
Note: to print sequence escapes give \\
#include <stdio.h> void main(){ printf (“Hello \\n World!”); } | #include<stdio.h> void main ( ){ printf (“Hello \\t World!”); } | #include<stdio.h> void main(){ printf(“Hello World” \\n); } |
o/p: Hello \n World | O/p: Hello \t World! | O/p: Error Note: Sequence escape always in between “ double quote” |
Remaining sequence escape please try yourself.
Comments
Post a Comment