title: Array dimension in C++
body: <p>I know that arrays need to be defined with a size that cannot be modified, but in this code, the counter i exceeds the size of the array (because of the 2 in &quot;i&lt;sz+2&quot; in the for loop) but the code don't give any errors, why?
  another question: is it correct to use std::cin to assign the value to sz or should I assign the value of sz when I declare the variable?</p>
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
      int sz;
      std::cin &gt;&gt; sz;
      int v[sz];
      std::cout &lt;&lt; &quot;i&quot; &lt;&lt; &quot; &quot; &lt;&lt; &quot;v[i]&quot; &lt;&lt; std::endl;
      for(int i=0;i&lt;sz+2;i++){
          std::cin &gt;&gt; v[i];
          std::cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; v[i] &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>