Question 4
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{3};
v.push_back(6);
v.push_back(9);
v[0] = 1;
std::cout << v.size() << ' ' << v.front() << ' ' << v.back() << ' ' << v[1] << '\n';
return 0;
}
- A 3 1 9 6 Correct
- B 4 1 9 6
- C 3 3 9 6
- D 5 1 9 6
Correct Answer: Option A
v{3} is one element; two push_backs make three. v[0] = 1 replaces the 3.
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!