C Special Characters
1. What are Special Characters in C?
-
Special characters are prefixed with a backslash
\. -
They are used for newline, tab, quotes, backslash, etc.
-
Mainly used in strings and character constants.
2. Common Special Characters (Escape Sequences)
| Escape Sequence | Description | Example Output |
|---|---|---|
\n |
Newline | Moves cursor to next line |
\t |
Horizontal tab | Adds tab spacing |
\\ |
Backslash | Prints \ |
\' |
Single quote | Prints ' |
\" |
Double quote | Prints " |
\a |
Alert / bell | Makes a beep sound |
\b |
Backspace | Deletes previous character |
\r |
Carriage return | Moves cursor to line start |
\v |
Vertical tab | Moves cursor down a vertical tab |
\0 |
Null character | Marks end of string |
\? |
Question mark | Prints ? |
\f |
Form feed | Moves cursor to next page (rarely used) |
3. Example – Using Newline \n and Tab \t
Output:
4. Example – Printing Quotes and Backslash
Output:
5. Example – Alert and Backspace
Output:
Notice
\bremoved the lastoinHello.
6. Key Points About Special Characters
-
Always use backslash
\to denote special characters. -
Can be used in strings (
" ") or character constants (' '). -
Useful for formatting output, path names, or control characters.
-
Some are rarely used today (
\f,\v), but basic ones (\n,\t,\\,\") are common.
