C Special Characters
🔣 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:
Output:
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)
Output:
✔ Moves cursor to next line
4️⃣ \t – Tab Space
Output:
✔ Adds horizontal spacing
5️⃣ \\ – Backslash
Output:
✔ Required because \ is escape starter
6️⃣ \" and \' – Quotes Inside String
7️⃣ \b – Backspace
Output:
✔ Removes previous character
8️⃣ \r – Carriage Return ⚠️
Output (system dependent):
✔ Cursor returns to beginning of line
9️⃣ \0 – Null Character (Very Important ⭐)
✔ Marks end of string
✔ Used internally by all C strings
🔟 Octal Escape Sequences
✔ Output: A
(101 is octal for ASCII 65)
1️⃣1️⃣ Hexadecimal Escape Sequences
✔ 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)
-
What is
\nin C? -
Difference between
\0and'0' -
Why
\\is used? -
What is escape sequence?
-
What happens if
\0is 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
