title: C++ filling a char array in a loop with user-input: what exactly is happening when a whole string is entered?
body: <p>I'm currently learning C++ and I guess I missed something fundamental. I'm having trouble understanding what exactly is happening here:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  
  int main(){
    int length = 0;
    std::cin &gt;&gt; length;
    char p[length];
  
    int i = 0;
    while(i &lt; length){
      std::cin &gt;&gt; p[i];
      std::cout &lt;&lt; ++i;
    }
    std::cout &lt;&lt; p;
  }
  </code></pre>
  
  <p>if I enter <code>5</code> as char-array length and then a whole string <code>abcdef</code> I will get <code>12345abcde</code>. </p>
  
  <p>I'm wondering why a string is acceptable input in the first place and why it still runs through the rest of the loop and increments <code>i</code> every time.
  I would've assumed the string is saved into the array (why is it okay that the string is longer than the array and no errors arise?) and then more input is expected - which would then be ignored (?) since the array is full. Or I would have expected an OOB like in Java.</p>