Sukhanov Niсkolay Sukhanov Niсkolay - 2 months ago 14
C++ Question

Is assignment operator in c++ returns rvalue or lvalue?

Is assignment operator in c++ returns rvalue or lvalue? And if it is lvalue, which of the two arguments will be incremented here?

(a = b)++

Answer

It returns a lvalue. Per § 5.17:

The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand.

If those objects have an user-defined operator for assignment, then it depends on implementation and declaration (return type) of the operator=.

So normally, after

(a = b)++

The object a will be incremented.

Comments