LearnFrenzy
Sign in Take a free test

Operator Overloading · Exercise 1 of 4

Operator Overloading Operator Overloading MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ operator overloading: rules, member vs non-member operators, comparisons and the spaceship operator, stream operators, increment, conversions and functors. Pick an option to check your answer instantly.

Question 1 Easy

What does operator overloading allow?

A Creating new operators like **
B Defining what existing operators mean for user-defined types
C Changing operator precedence
D Overloading operators for int and double
Question page & discussion
Question 2 Easy

Which of these operators cannot be overloaded?

A []
B ()
C ?:
D ->
Question page & discussion
Question 3 Easy

Which group contains only operators that can not be overloaded?

A :: . sizeof
B + - *
C << >> ==
D [] () ->
Question page & discussion
Question 4 Medium

Which operators must be overloaded as non-static member functions?

A + and -
B =, [], () and ->
C << and >>
D == and <
Question page & discussion
Question 5 Easy

Why is operator<< for printing a class written as a non-member (often a friend)?

A Members cannot return references
B The left operand is std::ostream, not your class; friend gives it access to private members
C It is faster
D The standard forbids member operators
Question page & discussion
Question 6 Easy

Which declaration overloads the postfix increment x++?

A T& operator++();
B T operator++(int);
C T operator++(T);
D T& operator++(++);
Question page & discussion
Question 7 Medium

What is the conventional return type of prefix operator++?

A void
B A reference to *this
C A copy of the old value
D bool
Question page & discussion
Question 8 Easy

Why does operator= conventionally return T& (*this)?

A To save memory
B So assignments can be chained: a = b = c
C It must return void
D To allow virtual dispatch
Question page & discussion
Question 9 Easy

After overloading + and * for a Vec class, how is a + b * c evaluated?

A Left to right: (a + b) * c
B a + (b * c) – precedence is unchanged
C It depends on the order of definition
D It does not compile
Question page & discussion
Question 10 Medium

Can you write int operator+(int a, int b)?

A Yes
B No – at least one parameter must be a class or enumeration type
C Only inside a namespace
D Only as a friend
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links