While trying to randomly access an empty vector in c++, there is segmentation fault.
vector<int> g;
cout<<g[3]; //Segmentation fault
But if we do a single push_back() operation, then we can do random access there is no error:
vector<int> g;
g.push_back(1);
cout<<g[0]; //output = 1
cout<<g[3]; //output = 0
What is the reason behind this??