
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- Escape sequences in Java
- What are the escape sequences supported by C#?
- How to process escape sequences in a string in Python?
- How can I remove the ANSI escape sequences from a string in python?
- The "" escape character in C#
- Escape The Ghosts in C++
- Validate Stack Sequences in C++
- Repeated DNA Sequences in C++
- Ways to print escape characters in C#
- C# Program to merge sequences
- JavaScript escape()
- Escape Characters in Python
- Escape characters in JavaScript
- Print all sequences of given length in C++
- Minimum Swaps To Make Sequences Increasing in C++

Advertisements