Understanding memory layout and constant storage in C++
This is a foundational C++ question that tests your grasp of where different types of data live in a program's memory. It asks you to reason concretely about the distinction between stack, heap, data segment, and read-only memory — and to trace how the compiler and linker place specific values.
Candidates typically need to identify the storage class and linkage of a given entity, understand how the compiler optimizes constant values, and know which region of memory (code segment, initialized data, uninitialized data, stack, or heap) holds the value in question. Getting this right requires familiarity with both the C++ standard and the typical layout of an executable on your target platform.
- Storage duration: static, automatic, dynamic, thread-local
- Memory segments: text, data, BSS, stack, heap
- Compiler optimizations for constants and literals
- Linkage and scope vs. storage location