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!