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

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

Challenge your C++ knowledge with a comprehensive quiz based on 'Thinking in C++'. Explore a variety of multiple choice questions with hints and explanations to solidify your understanding. Get prepared!

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 do const definitions default to internal linkage in C++?

  1. To allow for efficient constant folding

  2. To prevent linker errors from multiple definitions

  3. To enable easier optimization by the compiler

  4. To simplify code maintenance

The correct answer is: To prevent linker errors from multiple definitions

When using const definitions, the value of the constant is known at compile time. This means that the value doesn't need to be determined during runtime, which improves performance. However, this also means that the value of the constant can be changed by the compiler during the optimization process. By defaulting to internal linkage, const definitions are only accessible within the same translation unit, preventing unexpected changes to the value of the constant from other parts of the program. Options A, C, and D do not accurately explain why const definitions default to internal linkage and can be ruled out as incorrect choices.