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 must binary operators return when their effect is to produce a new value?

  1. A new modified object by reference

  2. A constant object by value

  3. Void

  4. A non-const reference to the modified object

The correct answer is: A constant object by value

Binary operators are functions that perform operations on two operands (inputs) and return a value. When these operators are used to produce a new value, they must return a value that represents the result of the operation. This means that options A, C, and D are incorrect. Option A states that the operator must return a new modified object by reference. However, this is incorrect because binary operators only return a value, not a reference to an object. Option C states that the operator must return void, which means the function will not return any value. This is incorrect because, in this context, the binary operator must return a value. Option D states that the operator must return a non-const reference to the modified object. However, this is incorrect because, as mentioned before, binary operators only return a value and not a reference to an object. Therefore, option B is the correct answer as