Multiple ChoiceBeginner 45s
Lambda capture by reference risk
A lambda captures a local by reference `[&x]` and is stored/returned to outlive the enclosing scope. Result?
Options
- 1The lambda copies x automatically at capture, so it stays safe outliving the scope.
- 2Compile error, because a captured reference cannot outlive the scope of its variable.
- 3A dangling reference: invoking the lambda later accesses a destroyed object (UB).
- 4The captured reference is promoted to shared_ptr, keeping the referent alive.
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.