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 the result of an object being passed by value to a function expecting a base class object?

  1. The object is sliced

  2. Virtual function mechanism improves

  3. Dynamic binding occurs

  4. Nothing, it's a normal operation

The correct answer is: The object is sliced

When an object is passed by value to a function expecting a base class object, the derived class object is "sliced" and only the base class data is passed into the function. This means that any additional data and behavior specific to the derived class will be lost, resulting in a base class object being passed to the function. Options B, C, and D are incorrect because they do not accurately describe the result of passing an object by value to a function expecting a base class object. Option B refers to virtual functions, which are not directly related to passing objects by value. Option C refers to dynamic binding, which occurs when an object is passed by reference or pointer to a function. Option D is incorrect because there is a significant difference between passing by value and passing by reference or pointer, and it is not a "normal operation" for an object to be sliced in this scenario.