Question 7
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <vector>
int main() {
std::vector<int> v{10, 20, 30, 40};
v.insert(v.begin() + 1, 15);
v.erase(v.begin() + 3);
v.insert(v.end(), 2, 99);
v.erase(v.begin());
for (int x : v) std::cout << x << ' ';
std::cout << '\n';
return 0;
}
- A 15 20 40 99 99 Correct
- B 15 20 30 99 99
- C 10 15 20 40 99
- D 15 30 40 99 99
Correct Answer: Option A
{10 15 20 30 40} → erase index 3 (30) → {10 15 20 40} → append two 99s → erase the first element.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!