What are Escape Sequences (Character Escapes) in C Language
Posted by divya on December 10 2015 02:14:12
One or more characters following ‘\’ (the backslash) is considered to be a single character and is called the escape sequence. For example:
\? 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 \b etc.
Escape sequences are used in a program to override the special meaning of characters in particular contexts! For example:
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
*/
Trigraphs
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 ]