#include
#include
using namespace std;

int main()
{
vector <int > vec (5);
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
vec.push_back(5);

for(auto it = vec.begin(); it != vec.end(); ++it)
cout << *it << \" \"; cout << endl << vec.size(); return 0; } [/sourcecode]

Predict the correct option for the above program
(A) 1 2 3 4 5
5
(B) 1 2 3 4 5
10
(C) 0 0 0 0 0 1 2 3 4 5
10
(D) None of the mentioned


Answer: (C)

Explanation: Vector initially has a capacity of 5 elements filled with zero during declaration. Inserting further elements in the vector increases its capacity, which becomes 10 after inserting 5 elements. begin() and end() are the iterators.

Quiz of this Question


  • Last Updated : 19 Nov, 2018

Share your thoughts in the comments