title: Array overflow (why does this work?)
body: <p>Okay, so I was teaching my girlfriend some c++, and she wrote a program that I thought wouldn't work, but it did. It accesses one more element in the array then there is (for instance, accessing array[5] for an array of size 5). Is this an instance of a buffer overflow? My thoughts on it are that it's writing to/accessing the memory directly after the array, is this correct? Basically my question here is..why does this work?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
  int size;
  
  cout &lt;&lt; "Please enter a size for the array." &lt;&lt; endl;
  cin &gt;&gt; size;
  cout &lt;&lt; endl;
  
  cout &lt;&lt; "There are " &lt;&lt; size &lt;&lt; " elements in this array." &lt;&lt; endl;
  cout &lt;&lt; endl;
  cout &lt;&lt; endl;
  cout &lt;&lt; endl;
  
  int array[size];
  
  for (int counter = 1; counter &lt;= size; counter++)
  
  {
      cout &lt;&lt; "Please enter a value for element " &lt;&lt; counter &lt;&lt; "." &lt;&lt; endl;
      cin &gt;&gt; array[counter];
  
  }
  
  cout &lt;&lt; endl;
  cout &lt;&lt; endl;
  
  
  for (int counter = 1; counter &lt;= size; counter++)
  
  {
      cout &lt;&lt; "Element " &lt;&lt; counter &lt;&lt; " is " &lt;&lt; array[counter] &lt;&lt; "." &lt;&lt; endl;
      cout &lt;&lt; endl;
  
  }
  
  cout &lt;&lt; "*bing! :)" &lt;&lt; endl;
  cout &lt;&lt; endl;
  
  
  return 0;
  }
  </code></pre>