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?
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Please enter a size for the array." << endl;
cin >> size;
cout << endl;
cout << "There are " << size << " elements in this array." << endl;
cout << endl;
cout << endl;
cout << endl;
int array[size];
for (int counter = 1; counter <= size; counter++)
{
cout << "Please enter a value for element " << counter << "." << endl;
cin >> array[counter];
}
cout << endl;
cout << endl;
for (int counter = 1; counter <= size; counter++)
{
cout << "Element " << counter << " is " << array[counter] << "." << endl;
cout << endl;
}
cout << "*bing! :)" << endl;
cout << endl;
return 0;
}