LearnFrenzy
Sign in Take a free test

References: lvalue and rvalue · References MCQ · Question 6

Why take a parameter as const T&? Answer, explanation & discussion

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

Why is void print(const std::vector<int>& v) a good signature?

  • A It copies the vector for safety
  • B It avoids copying the vector and guarantees the function will not modify it Correct
  • C It lets the function resize the vector
  • D It is required for vectors
Correct Answer: Option B

It also accepts temporaries, such as print({1, 2, 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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links