title: Use of null character in strings (C++)
body: <p>I am brushing up on my C++ and stumbled across a curious behavior in regards to strings, character arrays, and the null character (<code>'\0'</code>). The following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      cout &lt;&lt; "hello\0there"[6] &lt;&lt; endl;
  
      char word [] = "hello\0there";
      cout &lt;&lt; word[6] &lt;&lt; endl;
  
      string word2 = "hello\0there";
      cout &lt;&lt; word2[6] &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>produces the output:</p>
  
  <pre><code>&gt; t
  &gt; t
  &gt;
  </code></pre>
  
  <p>What is going on behind the scenes? Why does the string literal and the declared char array store the <code>'t'</code> at index 6 (after the internal <code>'\0'</code>), but the declared string does not?</p>