You can use one of several escape sequences within a character literal to represent a character that you can’t include directly in the literal.
The full list of character literals includes:
- \’ – Single quote (U+0027)
- \” – Double quote (U+0022)
- \\ – Backslash (U+005C)
- \a – Alert (U+0007)
- \b – Backspace (U+0008)
- \f – Form feed (U+000c)
- \n – New line (U+000A)
- \r – Carriage return (U+000D)
- \t – Horizontal tab (U+0009)
- \v – Vertical tab (U+000B)
1
2
3
4
5
6
7
8
9
10
| char single = '\'';char dquote = '\"';char backslash = '\\';char alert = '\a';char backspace = '\b';char formFeed = '\f';char newLine = '\n';char cr = '\r';char horizTab = '\t';char vertTab = '\v'; |
You can also use a backspace followed by 0 to indicate a null character.
1
| char nullChar = '\0'; |

