Escape Sequence in C Programming

Escape sequence in c programming; In this tutorial, i am going to show you what is escape sequence and how to use escape sequence in c programming.

What is Escape Sequence in C Programming

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.

List of Escape Sequences in C

Escape SequenceMeaning
\aAlarm or Beep
\bBackspace
\fForm Feed
\nNew Line
\rCarriage Return
\tTab (Horizontal)
\vVertical Tab
\\Backslash
\’Single Quote
\”Double Quote
\?Question Mark
\nnnoctal number
\xhhhexadecimal number
\0Null

Here are some basic examples of escape sequence characters in c; as shown below:

  • \n Escape Sequence
  • \t Escape Sequence
  • \b Escape Sequence
  • \a Escape Sequence

\n Escape Sequence

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

Output

Hello
Programmer

\t Escape Sequence

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

Output

Hello        Programmer

\b Escape Sequence

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

Output

Hell Programmer

Note that :- \b will backspace a character.

\a Escape Sequence

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

Output

This will make a bell sound

Note that :- \a will audio you a bell sound 🔔.

Conclusion

Thus, the article covered in detail about the various escape sequences available in c. Also, the article covered the various escape sequences by explaining some with appropriate examples.

More C Programming Tutorials

Leave a Comment