From the C++ Standard
5.17 Assignment and compound assignment operators [expr.ass] 1 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. The result
in all cases is a bit-field if the left operand is a bit-field. In all
cases, the assignment is sequenced after the value computation of the
right and left operands, and before the value computation of the
assignment expression.
And an example from there
int a, b;
a = b = { 1 }; // meaning a=b=1;
From the C Standard
6.5.16 Assignment operators Semantics 3 An assignment operator stores a value in the object designated by the left operand. An assignment
expression has the value of the left operand after the assignment,111)
but is not an lvalue. The type of an assignment expression is the type
the left operand would have after lvalue conversion. The side effect
of updating the stored value of the left operand is sequenced after
the value computations of the left and right operands. The evaluations
of the operands are unsequenced.
As you see there is a difference. In C++ the assignment operator returns an lvalue referring to the left operand while in C it returns the value of the left operand after the assignment,111)
but is not an lvalue.
It means that in C++ the following code is valid
int a, b = 20;
( a = 10 ) = b;
while in C the compiler shall issue an error.
a
,b
andc
are not the same variable? If they are the same it is more intereting. – Sebastiansebastianoa=b=c
is equivalent toa=(b=c)
and this is no different, in essence, thana=b+c
. – Knesset