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.


What is true about defining variables anywhere within the scope in C++ compared to C?

  1. It's illegal in both C++ and C

  2. It was introduced to support object construction with initialization

  3. It is only allowed in C, not in C++

  4. It is a compiler-specific feature, not part of the language

The correct answer is: It was introduced to support object construction with initialization

In C++, variables can be defined anywhere within the scope, including inside functions, while in C, variables have to be defined at the beginning of a block. This feature was introduced in C++ to support object construction with initialization, making it a more convenient and readable option compared to C. The other options are incorrect because defining variables anywhere within the scope is not illegal in either C++ or C. It is also allowed in C++, and is not a compiler-specific feature, rather it is a part of the language itself.