Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape sequence for ? in c++

Tags:

I was looking at the escape sequences for characters in strings in c++ and I noticed there is an escape sequence for a question mark. Can someone tell me why this is? It just seems a little odd and I can't figure out what ? does in a string. Thanks.

like image 605
Anon Avatar asked Oct 19 '09 03:10

Anon


People also ask

How many escape sequence are there in C?

There are 15 types of escape sequence in C to achieve various purposes.

What is \r used for in C?

When writing to an interactive terminal on stdout or stderr , '\r' can be used to move the cursor back to the beginning of the line, to overwrite it with new contents.


1 Answers

It's to keep a question mark from getting misinterpreted as part of a trigraph.

For example, in

"What??!" 

The "??! would be interpreted as the | character. So, you have to escape the question marks as follows:

"What\?\?!" 

Example complements of http://msdn.microsoft.com/en-us/library/bt0y4awe%28VS.80%29.aspx

like image 111
James McNellis Avatar answered Sep 18 '22 21:09

James McNellis