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 behavior of a const reference in C++ when binding to a temporary object?

  1. It extends the lifetime of the temporary object to the lifetime of the reference

  2. It creates a copy of the temporary on the stack

  3. It immediately destroys the temporary object

  4. It converts the temporary into a dynamic object

The correct answer is: It extends the lifetime of the temporary object to the lifetime of the reference

A const reference in C++ extends the lifetime of the temporary object it is bound to, ensuring that the object remains valid for the duration of the reference. The other options are incorrect because creating a copy on the stack would not maintain the original object, immediately destroying the temporary is not the behavior of a reference, and converting the temporary into a dynamic object would not extend its lifetime to the reference.