Practice · 1 of 2
std::optional divide
CHALLENGE
Difficulty: intermediate+25 XP
Implement std::optional<int> safe_divide(int a, int b): return the quotient when b != 0, and std::nullopt when b == 0. No exceptions, no sentinel ints.
Press Submit to check your solution.
Back to lesson: Practice: optional and enum practice