Nearby lessons

21 of 124

C - Escape Sequences

Escape Sequences is one of the foundational topics in C programming. This lesson explains Common Escape Sequences and Program: escape sequences in action with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

Common Escape Sequences

EscapeMeaning
\nNew line — move to the next line
\tTab — move to the next tab stop
\bBackspace
\"Print a double quote
\\Print a backslash
%%Print a percent sign
In simple words: an escape sequence is a secret code inside the quotes that starts with \ — \n means new line, \t means tab. The code is not printed; its effect is.

Program: escape sequences in action

Example02
CCode Cell
1#include <stdio.h>
2 
3void main()
4{
5 printf("Name\tMarks\n"); // tab between columns
6 printf("Rahul\t87\n");
7 printf("Priya\t95\n");
8 printf("I said \"Hello\" \\ done\n"); // quotes and backslash
9 printf("Percent sign: %%\n"); // prints %
10}
Output

Name	Marks
Rahul	87
Priya	95
I said "Hello" \ done
Percent sign: %
      
📝 Key Takeaways
  • printf() outputs; scanf() inputs (from stdio.h).
  • Format specifiers: %d int, %f float, %.2f two decimals, %c char, %s string.
  • Escape sequences: \n new line, \t tab, \\ backslash, %% percent.
  • scanf needs & before variables (except strings).
  • getchar()/putchar() handle one character.
  • getch/getche are Windows-only; prefer standard getchar.

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2