Escape sequence in C with examples
Escape sequence is combination of backward slash followed by one or more character which perform specific task.
Like /n represent newline and where ever compiler finds /n it move to new line.
There are many escape sequences in C and they are given in the table below
Character | Escape Sequence |
New line | \n |
Horizontal Tab | \t |
Vertical Tab | \v |
Quotation Mark | \" |
Apostrophe | \' |
Backslash | \\ |
Question Mark | \? |
Backspace | \b |
Bell Alert | \a |
Form Feed | \f |
Carriage Return | \r |
Null | \0 |
Where to use these Escape sequence ?
well the use of escape sequence is very frequent in C like you have to change lines using \n . By default all the text output using printf function will be displayed in single line.
Also horizontal tab can be used for better formatting of output .
Bell alert can be used in case of error message display .
Question mark can be used in questions and sometime apostrophe and quotation may be required.
so you can use these escape sequence as per need . Some used code is given below you can copy and run that code in codeblock or mobile C