title: Dynamic vs Static memory allocation
body: <p>So you can use the "new" operator to allocate memory dynamically at run-time. But what about the following case:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main ()
  {
      int size;
  
      cin &gt;&gt; size;
  
      int a[size];
  }
  </code></pre>
  
  <p>Here the size of the array cannot possibly be known at compile time, and it is determined at run-time. How is this different than dynamically allocated memory?</p>
  
  <p>This question is partly motivated by the statement on <a href="http://www.cplusplus.com/doc/tutorial/dynamic/" rel="nofollow">this</a> page:</p>
  
  <blockquote>
    <p>There is a substantial difference between declaring a normal array and allocating dynamic memory for a block of memory using new. <strong>The most important difference is that the size of a regular array needs to be a constant expression, and thus its size has to be determined at the moment of designing the program, before it is run, whereas the dynamic memory allocation performed by new allows to assign memory during runtime using any variable value as size.</strong></p>
  </blockquote>