All challenges
Multiple ChoiceIntermediate 45s

optional value access errors

What happens if you call `*opt` or `opt.value()` on a disengaged `std::optional`?
Options
  1. 1`*opt` is UB; `value()` throws std::bad_optional_access (or aborts without exceptions).
  2. 2Both operations return a default-constructed T instead of failing.
  3. 3Both operations throw std::runtime_error, since optional has no value to hand back.
  4. 4`*opt` returns std::nullopt in a disengaged state; `value()` is UB in that same state.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle