Question 5
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> a(5, 2), b{5, 2}, c(5), d{5};
std::cout << a.size() << b.size() << c.size() << d.size() << ' ' << a[4] << b[0] << c[4] << d[0] << '\n';
return 0;
}
- A 5251 2505 Correct
- B 2525 2505
- C 5251 5205
- D 5555 2205
Correct Answer: Option A
(5, 2) is five 2s; {5, 2} is the elements 5 and 2; (5) is five 0s; {5} is a single 5. So sizes 5, 2, 5, 1 and values 2, 5, 0, 5.
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!