int main()
{
vector<int> v(5);
v[0]=0; v[1]=1; v[2]=2; v[3]=3; v[4]=4;
for (int i=0; i<v.size(); i++)
v.pop_back();
for (int i=0; i<v.size(); i++)
cout<<v[i];
cout<<"\n";
return 0;
}
i am confused as to why the output is “01”. i would think the output is “0”
Trace each iteration of the first for-loop through:
And the loop stops there (not popping when i == 3) since
3 < 2is false. So the final contents ofvafter the loop is [ 0, 1 ].