Vectors are inbuilt dynamic arrays. We don't need to define size at the beginning.
Vectors are template array.
Don't use [] for inserting elements. Use it for getting value or updating the value. these will overwrite above values as for push_back still last element is at 2nd position
Initially capacity will come as 0. Actually underlying array is null at the beginning.
In push_back method current capacity will be seen whether we need to increase capacity or not.
v[4] = 500; We do directly this then vector won't be thinking about space and whether capacity needs to be increased or not. It might happen that we are not writing to the memory alloted to the array. The memory where we might be writing might not belong to us also.
cout << v[4] << endl; This won't throw error even if the position has garbage value.
cout << v.at(6) << endl; This will throw error out of range.