Notes – Escape Sequence in C

Escape sequences are special characters used in C to represent actions like a new line, tab space, or printing special characters.

They begin with a backslash \, followed by a character that represents a specific control instruction.

These are mostly used inside character and string literals.


Why Use Escape Sequences?

  • To format output.
  • To control special characters that cannot be typed directly.
  • To print quotes, backslashes, etc. inside strings.

Commonly Used Escape Sequences


Escape SequenceMeaningExampleOutput Description
\nNew lineprintf("Hello\nWorld");Prints “Hello”, then “World” on the next line
\tHorizontal tabprintf("Name\tAge");Inserts a tab between “Name” and “Age”
\\Backslashprintf("C:\\Files");Prints a single backslash \
\'Single quoteprintf("It\'s done");Prints single quote '
\"Double quoteprintf("She said \"Hi\"");Prints double quotes inside text
\rCarriage return (rarely used)Moves cursor to beginning of line (used in console apps)
\bBackspaceprintf("A\bB");Removes previous character
\aAlert (beep sound)printf("\a");Triggers system beep (if supported)
\0Null character (end of string)Used to terminate strings

Example Code

#include <stdio.h>

int main() {
printf("Line1\nLine2\n");
printf("Tab\tSpace\n");
printf("Path: C:\\Program Files\\\n");
printf("Quote: \"Hello World\"\n");
return 0;
}