What this C++ memory-layout interview question tests
This is a medium-difficulty question about how C++ compilers organize data in memory. It asks you to reason about the actual size of a class or struct at runtime, which depends on alignment rules, padding, and compiler-specific behavior—not just the sum of member sizes.
To answer correctly, you need to understand alignment requirements for fundamental types, how the compiler packs (or doesn't pack) members sequentially, and what the sizeof operator reports. This skill matters because incorrect assumptions about memory layout can lead to subtle bugs in systems code, serialization routines, and performance-critical paths.
- Type alignment and stride in memory
- Padding between and after members
- Compiler-dependent layout rules
- The difference between minimum theoretical and actual size