title: Interesting behavior with dynamically allocated array
body: <p>So I'm working with a dynamically allocated array, and I've set it to hold 5 elements, which should thus be 0-4. I made a function to reserve it if necessary, but I wanted to see if I was getting the program crash I expected when I assigned a value to the array at [5]. But, no error, not until [6].</p>
  
  <p>Here's my code:</p>
  
  <pre><code>int* dynamic_arr;
  dynamic_arr = new int[5];
  
  for(int i = 0; i &lt;= 100; i++){
      dynamic_arr[i] = i;
      used++;
      cout &lt;&lt; dynamic_arr[i]&lt;&lt;endl;
  }
  </code></pre>
  
  <p>Here's the output:</p>
  
  <pre><code>0 //i[0]
  1 //i[1]
  2 //i[2]
  3 //i[3]
  4 //i[4]
  5 //i[5]  &lt;-- should be out of range
  </code></pre>
  
  <p>After that it crashes.</p>
  
  <p>Why am I able to assign a value to a portion of the array that is, well, out of range for lack of a better term?</p>
  
  <p>Thanks</p>
  
  <p>OpSrcFTW</p>
  
  <p>EDIT: Appreciate the answers guys, thanks. I'll read more before posting for a quick answer next time, sorry. </p>