title: Why is "\?" an escape sequence in C/C++?
body: <p>There are four special non-alphabet characters that need to be escaped in C/C++: the single quote <code>\'</code>, the double quote <code>\"</code>, the backslash <code>\\</code>, and the question mark <code>\?</code>. It's apparently because they have special meanings. <code>'</code> for single <code>char</code>, <code>"</code> for string literals, <code>\</code> for escape sequences, but why is <code>?</code> one of them?</p>
  
  <p>I read the table of escape sequences in a textbook today and I realized that I've <strong>never</strong> escaped <code>?</code> before and have never encountered a problem with it. Just to be sure, I tested it under GCC:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(void)
  {
      printf("question mark ? and escaped \?\n");
      return 0;
  }
  </code></pre>
  
  <p>And the C++ version:</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main(void)
  {
      std::cout &lt;&lt; "question mark ? and escaped \?" &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Both programs output:  <code>question mark ? and escaped ?</code></p>
  
  <p>So I have two questions:</p>
  
  <ol>
  <li>Why is <code>\?</code> one of the escape sequence characters?</li>
  <li>Why does non-escaping <code>?</code> work fine? There's not even a warning.</li>
  </ol>
  
  <hr>
  
  <p>The more interesting fact is that the escaped <code>\?</code> can be used the same as <code>?</code> in some other languages as well. I tested in Lua/Ruby, and it's also true even though I didn't find this documented.</p>