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 (\).
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:
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 |
\n – New Line (Most Used)
Output:
- Moves cursor to next line
\t – Tab Space
Output:
- Adds horizontal spacing
\\ – Backslash
Output:
- Required because
\is escape starter
\" and \' – Quotes Inside String
\b – Backspace
Output:
- Removes previous character
\r – Carriage Return
Output (system dependent):
- Cursor returns to beginning of line
\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)
Hexadecimal Escape Sequences
Output: A
(41 is hex for ASCII 65)
Special Characters vs Normal Characters
- Different meanings
Common Mistakes
- Forgetting
\ Using\noutside string or char- Confusing
\0with'0' Expecting\bto 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\nand\tare most common\0terminates strings- Must-know for interviews & real coding
