C Special Characters

C Tutorial

🔣 C Special Characters (Escape Sequences) – Complete Guide

In C language, special characters (also called escape sequences) are used to represent non-printable characters or to give special meaning inside strings and character literals.

They always start with a backslash (\).


1️⃣ What Are Special Characters in C?

Special characters are escape sequences that tell the compiler to perform a special action, such as a new line, tab, beep sound, etc.

Example:

printf("Hello\nWorld");

Output:

Hello
World

2️⃣ Most Common Special Characters ⭐

Escape Meaning
\n New line
\t Horizontal tab
\r Carriage return
\b Backspace
\f Form feed
\v Vertical tab
\\ Backslash
\' Single quote
\" Double quote
\? Question mark
\0 Null character

3️⃣ \n – New Line (Most Used)

printf("C\nProgramming");

Output:

C
Programming

✔ Moves cursor to next line


4️⃣ \t – Tab Space

printf("Name\tAge");

Output:

Name Age

✔ Adds horizontal spacing


5️⃣ \\ – Backslash

printf("C:\\Program Files\\");

Output:

C:\Program Files\

✔ Required because \ is escape starter


6️⃣ \" and \' – Quotes Inside String


7️⃣ \b – Backspace

printf("AB\bC");

Output:

AC

✔ Removes previous character


8️⃣ \r – Carriage Return ⚠️

printf("Hello\rWorld");

Output (system dependent):

World

✔ Cursor returns to beginning of line


9️⃣ \0 – Null Character (Very Important ⭐)

char name[] = {'C','o','d','e','\0'};

✔ Marks end of string
✔ Used internally by all C strings


🔟 Octal Escape Sequences

printf("\101");

✔ Output: A
(101 is octal for ASCII 65)


1️⃣1️⃣ Hexadecimal Escape Sequences

printf("\x41");

✔ Output: A
(41 is hex for ASCII 65)


1️⃣2️⃣ Special Characters vs Normal Characters


✔ Different meanings


1️⃣3️⃣ Common Mistakes ❌

❌ Forgetting \
❌ Using \n outside string or char
❌ Confusing \0 with '0'
❌ Expecting \b to work in all terminals


📌 Interview Questions (Very Important)

  1. What is \n in C?

  2. Difference between \0 and '0'

  3. Why \\ is used?

  4. What is escape sequence?

  5. What happens if \0 is missing in string?


🔥 Real-Life Use Cases

  • Formatting output

  • String handling

  • File writing

  • Console UI alignment

  • Embedded & system programming


✅ Summary

Special characters start with \
✔ Used for formatting & control
\n and \t are most common
\0 terminates strings
✔ Must-know for interviews & real coding

You may also like...