Escape Sequence in C

An escape sequence allow special characters to be put into the source code. It is a sequence of characters that doesn't represent itself when used inside string literal or character.

It is composed of two or more characters starting with backslash \.

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

Escape Sequence Example

snippet
#include  
int main(){  
	 int number=50;
	printf("You\nare\nlearning\n\'c\' language\n\"Do you know C language\"");   
return 0;
}
Output
You are learning 'c' language "Do you know C language"
snippet
printf("\12");
Produces the decimal character 10 (x0A Hex).

printf("\xFF");
Produces the decimal character -1 or 255 (depending on sign).

printf("\x123");
Produces a single character (value is undefined). May cause errors.

printf("\0222");
Produces two characters whose values are implementation-specific.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +