According to Operator Priority , the comma operator has lower priority than operator= , so x = 2,3; equivalently (x = 2),3; . (The operator’s priority determines how the operator will be tied to its arguments, which are tougher or weaker than other operators, according to their priorities.)
Note that the expression for the comma (x = 2),3 here, not 2,3 . First, x = 2 is evaluated (and its side effects are completed), then the result is discarded, then 3 is evaluated (actually does nothing). Therefore, the value of x is 2 . Note that 3 is the result of the entire comma expression (i.e. x = 2,3 ), it will not be used to assign x . (Change it to x = (2,3); x will be assigned 3 )
For return 2,3; a comma expression 2,3 , 2 is evaluated, then its result is discarded, and then 3 is evaluated and returned as the result of the entire comma expression, which returns a return statement later.
Additional Information on Expressions and Statements
An expression is a sequence of operators and their operands that defines a calculation.
x = 2,3; expression expression , x = 2,3 is the expression here.
An expression followed by a semicolon is an expression.
Syntax: attr(optional) expression(optional) ; (1) attr(optional) expression(optional) ; (1)
return 2,3; return statement , 2,3 is the expression here.
Syntax: attr(optional) return expression(optional) ; (1) attr(optional) return expression(optional) ; (1)