I'm starting to learn C++ so the answer to my question might be obvious to you but I am really puzzled. I expect the program would crash when accessing a out of range index but instead, the program runs just fine. Here is the code.
#include <iostream>
#include <typeinfo>
#include <string>
#include <vector>
using namespace std;
int main() {
int x;
vector<int> v1;
while (cin >> x) {
v1.push_back(x);
}
cout << "out of bound: " << v1[10] << endl;
return 0;
}
And here is the output:
1 2 3
out of bound: 0