What this C++ memory-management code-review question tests
This is an easy code-review question that asks you to spot a common memory-management error in a C++ snippet. It's the kind of problem used in initial screening rounds to verify that candidates understand the basics of resource ownership and cleanup.
The question rewards careful reading: you'll need to trace through the code, identify where memory is allocated, and determine whether it's guaranteed to be freed. Pay special attention to control flow, function returns, and exception safety. Firms ask these because shipping code with memory leaks is costly, and catching such issues early in a code review is a valuable skill.
- Stack vs. heap allocation
- Pointer lifecycle and responsibility
- Exception safety and cleanup guarantees
- Smart pointers as an alternative to manual management