logo CodeStepByStep logo

vectorMysteryInsert

Language/Type: C++ Vector collections

What are the contents of the vector after the following code executes?

Vector<int> vec;
for (int i = 1; i <= 5; i++) {
    vec += 2 * i;         // {2, 4, 6, 8, 10}
}
int size = vec.size();
for (int i = 0; i < size; i++) {
    vec.insert(i, 42);    // add 42 at index i
}
cout << vec << endl;
vector contents

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.