Question 6
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
#include <tuple>
std::tuple<int, int, int> rgb() { return {255, 128, 0}; }
int main() {
auto [r, g] = rgb();
std::cout << r << ' ' << g << '\n';
return 0;
}
- A tuple needs <utility>
- B The tuple has 3 elements, so the structured binding must declare exactly 3 names: auto [r, g, b] = rgb(); Correct
- C r and g must be int
- D rgb must return a struct
Correct Answer: Option B
There is no way to skip elements (use [[maybe_unused]] or std::get for one 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!