logo CodeStepByStep logo

vectorMysteryInsert

Language/Type: C++ Vector collections
Author: Marty Stepp (on 2016/06/16)

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

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.