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 the C++ compiler ensure that a call to a virtual function binds to the correct function body at runtime?

  1. By creating a fixed function lookup table at compile time

  2. Using a virtual table (VTABLE) and a virtual pointer (VPTR) mechanism

  3. By recompiling parts of the code at runtime

  4. C++ does not support runtime binding

The correct answer is: Using a virtual table (VTABLE) and a virtual pointer (VPTR) mechanism

The C++ compiler ensures that a call to a virtual function binds to the correct function body at runtime by using a virtual table (VTABLE) and a virtual pointer (VPTR) mechanism. This means that there is a table of function pointers that the compiler creates at compile time, and a virtual pointer references this table at runtime to determine which function to call. Option A is incorrect because the virtual table is not fixed and can be modified at runtime. Option C is also incorrect because the code itself is not recompiled, but the virtual table is dynamically updated. Option D is also incorrect because C++ does support runtime binding through the use of virtual functions.