Escape Sequences in C

This C Tutorial explains Escape Sequences/Character Escapes and why they are needed.

What is an Escape Sequences in C?
One or more characters following ‘\’ (the backslash) is considered to be a single character and is called the escape sequence.

List of Escape Sequences in C:

  • \? used to write multiple question marks from being interpreted as trigraphs in printf() statements.
  • \” used to get the quotation marks inside the string literals.
  • \’ used to write a character literal for a character.
  • \\ used to write a backslash from being interpreted as a character escape.
  • \a used for alert or beep.
  • \b used for backspace
  • \0 used for Null value.
  • \n is used to insert new line.
  • \t is used for tabspace.
  • \nnn is commonly used to represent an octal number.
  • \xhh is used to represent an hexadecimal number.

Escape sequences are used in a program to override the special meaning of characters in particular contexts!

For example:

Example 1:

printf("What is your name? Are you \"some Xyz\"?");    
 * OUTPUT: What is your name? Are you "some XYZ"?
 * Note the Name in output enclosed in Quotation Marks

Example 2:

int main()
    printf("Learn more about \t escape sequences\n");
    printf("@ Sanfoundry");
    return (0);


Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Learn more about 	 escape sequences
@ Sanfoundry



Trigraphs are all three-lettered characters, all begin with ?? (double question marks) followed by a character, represent some other character. Basically, they are used to complement a Character Set lacking for some characters. For example:

??( represent [
??) represent ]

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.