Machine-translated by Google. Questions are authored in English.
Top

Discussion

If an arithmetic assignment operator is overloaded in C++ programming the result :

  • A.Goes in the object to the right of the operator
  • B.Goes in the object to the left of the operator
  • C.Must be returned
  • D.Goes in the object to the left of the operator is a member

Answer: B

The result goes in the object to the left of the operator.

Arithmetic assignment operators such as += and -= modify their left operand. When += is overloaded as a member function, a += b is called as a.operator+=(b): the object on the left is the one that calls the function, and the function changes that object's own data.

The object on the right is only read. The operator may also return a reference to the left object so that assignments can be chained, but returning a result is not required, and the result is stored in the left object whether or not anything is returned.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.