LearnFrenzy
Sign in Take a free test

Functions and Default Arguments · Functions MCQ · Question 17

How to unpack a returned pair in C++17 Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 17 Back to Exercise

A function returns std::pair<int, int>. Which line unpacks it into two variables (C++17)?

  • A int a, b = f();
  • B auto [a, b] = f(); Correct
  • C auto (a, b) = f();
  • D pair a, b = f();
Correct Answer: Option B

Structured bindings work with pairs, tuples, arrays and structs with public members.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links