Reputation: 1652
Why aren't \a
(beep),\v
(vertical tab) not working in my program even though they are standard according to the links below?And why is a single quotation mark working even without using it as \'
? And finally,is \?
an escape character at all as that Microsoft site says,because I use the ? symbol inside a printf()
format string without \
and it works fine.
To put it clearly:
Why are \a
and \v
not working?
Why single quote works without the \
even though \'
is an escape sequence?
\?
an escape sequence?(The link says so but ? works without the \
)http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx http://en.wikipedia.org/wiki/Escape_sequences_in_C
Upvotes: 0
Views: 2478
Reputation: 545913
- Why are
\a
and\v
not working?
Because the console you’re using doesn’t support them. The compiler does, and produces the correct character code in the output, but the terminal emulator ignores them.
- Why single quote works without the
\
even though\'
is an escape sequence?
Because it’s unnecessary to escape it in strings, you only need to escape it in a char
literal. Same for \"
for string
literal:
"'"
vs. '\''
'"'
vs. "\""
- Is
\?
an escape sequence? (The link says so but?
works without the\
)
The link actually says something different:
Note that …
\?
specifies a literal question mark in cases where the character sequence would be misinterpreted as a trigraph
It’s only there to avoid ambiguity in cases where the following characters would form a valid trigraph, such as ??=
(which is the trigraph for #
). If you want to use this sequence in a string, you need to escape the first (or second) ?
.
Upvotes: 2
Reputation: 7610
Some of the escape sequences are device specific. So they don't produce the desired on effect on every device. For example, the vertical tab (\v
) and form feed (\f
) escape sequences do not affect screen output. But they do perform the appropriate printer operations.
Upvotes: 0