- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Escape sequences in C
Many programming languages support a concept called Escape Sequence. When a character is preceded by a backslash (\), it is called an escape sequence and it has a special meaning to the compiler. For example,
in the following statement is a valid character and it is called a new line character −
char ch = '
';
Here, character n has been preceded by a backslash (\), it has special meaning which is a new line but keep in mind that backslash (\) has special meaning with a few characters only. The following statement will not convey any meaning in C programming and it will be assumed as an invalid statement −
char ch = '\1';
The following table lists the escape sequences available in C programming language −
Sr.No | Escape Sequence & Description |
---|---|
1 | \t Inserts a tab in the text at this point. |
2 | \b Inserts a backspace in the text at this point. |
3 | Inserts a newline in the text at this point. |
4 | \r Inserts a carriage return in the text at this point. |
5 | \f Inserts a form feed in the text at this point. |
6 | \’ Inserts a single quote character in the text at this point. |
7 | \” Inserts a double quote character in the text at this point. |
8 | \ Inserts a backslash character in the text at this point. |
Example
#include <stdio.h> int main() { char ch1; char ch2; char ch3; char ch4; ch1 = '\t'; ch2 = '
'; printf( "Test for tabspace %c and a newline %c will start here", ch1, ch2); }
Output
Test for tabspace and a newline will start here
Advertisements