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:
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
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:
#include<stdio.h> int main() { printf("Learn more about \t escape sequences\n"); printf("@ Sanfoundry"); return (0); }
Output:
Check this: BCA MCQs | Computer Science Books
Learn more about escape sequences @ Sanfoundry
Trigraphs
advertisement
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.
advertisement
If you wish to look at all C Tutorials, go to C Tutorials.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for Computer Science Internship
- Buy Computer Science Books
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Practice BCA MCQs