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.


How can you extend a namespace with additional definitions in C++?

  1. using namespace extension;

  2. namespace name::extension;

  3. extend namespace name { ... }

  4. namespace name { ... }

The correct answer is: namespace name { ... }

Namespaces in C++ are used to group related code and avoid naming conflicts. In order to add additional definitions to an existing namespace, you simply use the same namespace name followed by curly brackets containing the new definitions. Option A and B are incorrect because they use incorrect syntax and would likely lead to errors when compiling the code. Option C is incorrect because it suggests creating a new namespace instead of extending an existing one. Therefore, option D is the correct and preferred way to extend a namespace with additional definitions.