It is the comma operator, mostly useful with side-effecting expressions like foo = (bar1++, f(bar2));
which increments bar1
, call function f
with bar2
and set its result to foo
In C the comma operator has lower precedence than assignment.
In general e1,e2
(in expression context) evaluates the left operand e1
, discards its result, then evaluate the right operand e2
and gives the value of the right operand (as the value of the entire e1,e2
expression).
Ocaml has the ;
operator, Scheme has begin
, Lisp has progn
for similar purposes (evaluating two or several sub-expressions for side effects, and giving the last as the entire result).
74. http://en.wikipedia.org/wiki/Comma_operator "In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type)." but assignment is a higher precedence, so it assigns first then discards. – Paul Tomblin Aug 29 '13 at 17:34