Escape Sequences in C

In this tutorial, you will learn about escape sequences in the C programming language with the help of examples.


An escape sequence in the C programming language is a sequence of characters that does not represent itself when used inside a character or a string literal but has its own specific meaning.

Each escape sequence comprises two or more characters starting with a backslash \ and followed by any other valid character set in C language. For example, \n is an escape sequence that represents a new line.

The concept of escape sequences first developed in the C language and implemented in other languages such as C++, Java, etc.

List of Escape Sequences in C

Escape Sequence Description
\a Alarm or Beep
\b Backspace
\e Escape character
\f Form Feed
\n New Line
\r Carriage Return
\t Tab (Horizontal)
\v Vertical Tab
\\ Backslash
\’ Single Quote
\” Double Quote
\? Question Mark
\nnn octal number
\xhh hexadecimal number
\0 Null

Escape Sequence Example

Let’s check an example of an escape sequence.

#include<stdio.h> 
int main(){
printf("Welcome!\nTo the world of\nC Progamming langauge\nAnd\n\"You are learning escape sequence\""); 
return 0; 
}

Output

Welcome!
To the world of
C Progamming langauge
And
“You are learning escape sequence”

Please get connected & share!

Categories

Advertisement