LearnFrenzy
Sign in Take a free test

Modern C++ Features (C++11 to C++23) · Modern C++ MCQ · Question 10

Scope of a variable declared in an if initialiser Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

In if (auto it = m.find(k); it != m.end()) { … } else { … }, where can it be used?

  • A Only in the if branch
  • B In the condition, the if branch and the else branch, but not after the statement Correct
  • C Everywhere in the function
  • D Only in the condition
Correct Answer: Option B

It keeps helper variables out of the surrounding scope.

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