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.


What does the 'sizeof' operator return when applied to a class derived through inheritance?

  1. The size of the base class

  2. The size of the derived class

  3. The combined size of the base and derived classes

  4. Cannot be determined

The correct answer is: The size of the derived class

The 'sizeof' operator returns the size of the derived class when applied to a class derived through inheritance. This is because a derived class inherits all of the non-static members and member functions of the base class, thus the size of the derived class includes the size of the base class as well. Options A and C are incorrect as they refer to the size of the base and derived classes combined, while option D is incorrect as it implies that the 'sizeof' operator cannot determine the size of a derived class, which is not true.