LearnFrenzy
Sign in Take a free test

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

What is std::optional for? Answer, explanation & discussion

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

When should a function return std::optional<int>?

  • A When it returns several ints
  • B When there may legitimately be no result, e.g. "not found" Correct
  • C When the int is very large
  • D When it throws
Correct Answer: Option B

It replaces sentinel values like -1 that could be valid results.

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