Hello, I'm trying to understand a piece of code I ran into. AS far as I knew, if you define an array of a certain size, then it could not be resized at execution time.
So what I do in the following code is define a global array with a size of 10, and then in the main function I initialize up to index 12, and yet get no errors and expected output. Can't tell what's going on. Hope someone could explain it, I've been researching but no luck yet. Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int array[10];
int main() {
int i = 0;
for(i=0; i <=12; i++) {
array[i] = 0;
}
for(i=0; i <=12; i++){
cout << "array[" << i<< "]=" << array[i] << endl;
}
}