Skip to main content
2 of 8
added 255 characters in body; added 94 characters in body
haccks
  • 105.9k
  • 27
  • 179
  • 271

In expression (i, ++i, 1), comma used is comma operator

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

Leftmost i will be evaluated and its value will be discarded. Then ++i will be evaluated and will increment i by 1 and again value of the expression ++i will be discarded, but side effect is permanent . Then 1 will be evaluated and the value of the expression will be 1.

It is equivalent to

i;
++i;
i = 1 + 1;
haccks
  • 105.9k
  • 27
  • 179
  • 271