title: Dynamic array without new (C++)
body: <p>I'm new to C++ and this is a very basic question. </p>
  
  <p>In C++ there are only two ways to create dynamic arrays <em>(read in a book, correct me if I'm wrong)</em> using memory allocation either by <code>new</code> operator or <code>malloc()</code> function which is taken from C. </p>
  
  <p>When declaring an array <code>int array[size]</code>, the square brackets <code>[]</code> <em>must</em> have a <code>const</code>. </p>
  
  <p>However in the following code <code>size</code> is an <code>unsigned int</code> variable. </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  int main() {
      using namespace std;
      unsigned int size;
      cout&lt;&lt;"Enter size of the array : ";
      cin&gt;&gt;size;
      int array[size]; // Dynamically Allocating Memory
      cout&lt;&lt;"\nEnter the elements of the array\n";
      // Reading Elements
      for (int i = 0; i &lt; size; i++) {
          cout&lt;&lt;" :";
          cin&gt;&gt;array[i];
      }
      // Displaying Elements
      cout&lt;&lt;"\nThere are total "&lt;&lt;size&lt;&lt;" elements, as listed below.";
      for (int j = 0; j &lt; size; j++) {
          cout&lt;&lt;endl&lt;&lt;array[j];
      }
      return 0;
  }
  </code></pre>
  
  <p>While compiling g++ throws no error and moreover the program runs perfectly. </p>
  
  <p><strong>Question 1 :</strong> Could this be another way to create dynamic array? </p>
  
  <p><strong>Question 2 :</strong> Is the code correct?</p>
  
  <p><strong>Question 3 :</strong> If <code>[]</code> can only contain <code>const</code>, why does the code work?</p>