title: C++ Accessing bounds outside static array vs new array?
body: <p>Why does the following  code compile and run.</p>
  
  <p>I have created an integer array and assigned its size to <code>10</code>, why then does the program not return an error that I am trying to access an element outside the array, when inside the for loop?</p>
  
  <p>In addition, I would like to understand the concept of new, is my usage correct(I have not assigned how much memory *arrays needs), it is my understanding that new allows me to create an array of dynamic size (meaning that I can increase the size of this array indefinitely during runtime, correct me if I am wrong). If this is correct what is the difference in me using new or simply just allocating array[]; since both apparently allow me to increase the size of my array at runtime as can be seen with this example. I know about scope, stack and heap differences, so assume that both variables are only declared in main and use the following code as the example.</p>
  
  <p><a href="http://ideone.com/Tbud1" rel="nofollow">http://ideone.com/Tbud1</a></p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
  int array[10];
  int *arrays;
  arrays = new int();
  for (int i=0; i&lt;450; i++)
  {
     arrays[i] = i;
     cout &lt;&lt; arrays[i] &lt;&lt; " ";
     array[i] = i;
     cout &lt;&lt; array[i] &lt;&lt; endl;
  }
  return 0;
  }
  </code></pre>