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 does adding a single virtual function affect the size of an object?

  1. Increases by the size of an int

  2. No change

  3. Increases by the size of a void pointer

  4. Decreases because of optimization

The correct answer is: Increases by the size of a void pointer

Adding a single virtual function does not affect the size of an object if the object already has virtual functions. This is because the object already contains a pointer to the virtual function table (vtable). However, if the object did not previously have virtual functions, adding a single virtual function will increase the size of the object by the size of a void pointer. This is because the vtable pointer needs to be added to the object's structure, which typically is the size of a void pointer. Therefore, options A, B, and D are incorrect because they do not accurately describe how adding a single virtual function affects the size of an object.