The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Escape Sequences

What Escape Sequences Means?

In C Programming, the word escape sequences means to escape the character from the sequences of words and give special meaning to the escaped character.

C Escape Sequences

Example

Let us consider the following word "hello\nworld". Clearly, n is the character which escapes from the sequences of word, helloworld and a special meaning is given to n i.e) new line.

Escape Sequences Facts

  • An Escape sequences are non-printing characters.
  • An Escape sequences are certain characters associated with  \  (backslash).
  • An Escape sequences always begin with  \  (backslash) and is followed by one character.
  • An Escape sequences are mostly used in printf() statement.

Escape Sequences Table

There are 12 escape sequences in C Programming. They are

Escape Sequence Use ASCII Value
\n New Line 010
\t Horizontal tab 009
\b Backspace 008
\r Carriage Return 013
\a Alert Bell 007
\' Single quote 039
\" Double quote 034
\? Question 063
\\ Backslash 092
\f Form feed 012
\v Vertical tab 011
\0 Null 000

\n Escape Sequence

newline.c
#include <stdio.h>
int main()
{
printf("Hello \nProgrammer ");
return 0;
}
  • Hello
  • Programmer

Note:

Statement followed by \n will be printed in New Line.

\t Escape Sequence

horizontalspaces.c
#include <stdio.h>
int main()
{
printf("Hello\tProgrammer ");
return 0;
}
  • Hello        Programmer

Note:

Statement followed by \t will be printed after 8 space.

\b Escape Sequence

backspace.c
#include <stdio.h>
int main()
{
printf("Hello\b Programmer ");
return 0;
}
  • Hell Programmer

Note:

\b will backspace a character.

\r Escape Sequence

returncarriage.c
#include <stdio.h>
int main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
return 0;
}
  • hai

Note:

  • \n will print its defined characters in New line. ie) ab.
  • \b will backspace a character. ie) asi.
  • \r will replace the existing characters by its defined characters(ha) ie) hai.

\a Escape Sequence

alarm.c
#include <stdio.h>
int main()
{
printf("This will make a bell sound\a ");
return 0;
}
  • This will make a bell sound

Note:

\a will audio you a bell sound 🔔.

\' Escape Sequence

singlequote.c
#include <stdio.h>
int main()
{
printf("\'Hello Programmer\' ");
return 0;
}
  • 'Hello Programmer'

Note:

\' will print single quote '.

\" Escape Sequence

doublequote.c
#include <stdio.h>
int main()
{
printf("\"Hello Programmer\" ");
return 0;
}
  • "Hello Programmer"

Note:

\"\" will print double quote ".

\? Escape Sequence

questionmark.c
#include <stdio.h>
int main()
{
printf("How are you\? ");
return 0;
}
  • How are you?

Note:

\? will print? (Question mark).

\\ Escape Sequence

backslash.c
#include <stdio.h>
int main()
{
printf("C\\learn\\from\\2braces.com ");
return 0;
}
  • C \ learn\ from\ 2braces.com

Note:

\\ will print a single backslash (\).

\f Escape Sequence

formfeed.c
#include <stdio.h>
int main()
{
printf("\f - female sign. ");
return 0;
}
  • ♀ - female sign.

Note:

\f will print female sign (♀).

\v Escape Sequence

formfeed.c
#include <stdio.h>
int main()
{
printf("\v - male sign. ");
return 0;
}
  • ♂ - male sign.

Note:

\v will print male sign (♂).

\0 Escape Sequence

formfeed.c
#include <stdio.h>
int main()
{
printf("Hello \0 Programmer ");
return 0;
}
  • Hello

Note:

The statement followed by \0 will not display.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report