What this C++ memory-allocation question tests
This is an easy question that checks whether you understand how the new operator allocates memory in C++, and how array allocation differs from scalar allocation. It is a quick diagnostic for foundational language knowledge rather than algorithmic thinking.
The question asks you to trace through a code snippet and reason about the exact number of bytes requested at the point of allocation. Success requires familiarity with C++ type sizes, array syntax, and the semantics of new. Interviewers often use this kind of question early in a conversation to establish baseline competence before moving to more complex logic or system design.
- Scalar vs. array allocation with
new - Type sizes and the
sizeof operator - Pointer semantics and memory layout