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.


Why is flexibility sacrificed when using static storage?

  1. Memory allocation is slower

  2. Exact object types must be known at compile-time

  3. Object quantities, lifetimes, and types cannot be known until runtime

  4. Static storage cannot store derived types

The correct answer is: Object quantities, lifetimes, and types cannot be known until runtime

Static storage is designed to store information permanently and is often allocated during compile-time, with the actual values assigned during runtime. The sacrifice of flexibility is a necessary trade-off for this permanence since stored objects must have fixed quantities, lifetimes, and types that can be determined at compile-time. This means that while it is possible to allocate memory quickly and efficiently with static storage, it also limits the program to only use objects with known quantities and types, unlike in dynamic storage where this can be determined during execution. This makes static storage unsuitable for storing derived types, as these types may not be known at compile-time and therefore cannot be allocated in static storage.