Some important/common instances of escape characters in
C++:
The first three examples exist because of the
whitespace element (
please see that writeup) and are
very common.
The last four examples (\,',",?) are necessary because the characters they represent are
control characters. They are part of the invisible
character set that makes up the code itself, much like
angled brackets in
HTML. In order for these symbols to appear upon execution, they must be preceded by a
backslash. For instance, if you wanted to display the text
How are you? you would have to put into the code
How are you\?. Otherwise, the compiler would interpret the question mark as
something that it's not - or, more simply, as
more than a question mark. (
I.E.: The
? is used to denote a
conditional operator.)
Escape characters may also be used in tandem with
hexadecimal numbers and
UCS codes to display other obscure letters/symbols; for instance, characters that aren't part of your language.