Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


In C++, where is the memory for static storage duration variables allocated?

  1. On the stack

  2. In the heap

  3. In the data segment

  4. At a random memory location

The correct answer is: In the data segment

Static storage duration variables in C++ are allocated memory in the data segment. The data segment is where global and static variables are stored, meaning they have a lifetime that extends throughout the entire program. Options A and B are incorrect because static storage duration variables are not allocated on the stack or in the heap. The stack is used for function calls and local variables, which have a shorter lifetime than static variables. The heap is used for dynamic memory allocation at runtime, but it does not allocate memory for static variables. Option D is incorrect because the memory for static storage duration variables is allocated in a specific location in the data segment, not at a random memory location.