What this C++ language-knowledge question tests
This is a medium-difficulty question that probes your understanding of a common pitfall in C++ loop semantics. It's the kind of gotcha that high-frequency trading firms ask to separate candidates who have debugged real code from those who have only read tutorials.
The question requires you to spot a subtle but dangerous behaviour in a for-loop construct—one that compiles and often runs, but violates the intent in ways that become obvious only under scrutiny or when the code is ported or refactored. Solving it demands familiarity with how the C++ standard defines loop scope, variable lifetime, and the order of operations within a loop header.
- Loop variable scope and re-initialization
- Temporal order of declarations and conditions
- Pre-C++23 vs. modern C++ loop semantics
- Why the compiler does not warn you