Search code examples
c++expressionoperator-precedence

Does an assignment operator in c++ return rvalue or lvalue?


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

(a = b)++

Solution

  • 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.