32
•In a C program, comma is used in two contexts: (1) A separator (2)
An Operator.
•int a=1, b=2, c=3, i=0; // commas act as separators in this line, not as
an operator
•i = (a, b); // stores b into i
•i = a, b; // stores a into i. Equivalent to (i = a), b;
•i = (a += 2, a + b); // increases a by 2, then stores a+b = 3+2 into i
•i = a += 2, a + b; // Equivalent to (i = (a += 2)), a + b;
•i = a, b, c; // Equivalent to (i=a),b,c
•i = (a, b, c); // stores c into i, discarding the unused a and b rvalues
•return a=4, b=5, c=6; // returns 6, not 4,
•return 1, 2, 3; // returns 3, not 1.
•return(1), 2, 3; // returns 3, not 1.
Comma Operator