The comma operator is primarily used for connection expressions, such as:
int a = 9;int b = 10;a = a+1, b = 3*4;
* An expression concatenated with the comma operator is called a comma expression, and its general form is:
Expression 1, expression 2, ..., expression n
The operation of the comma expression is: From left to right, evaluates expression 1, evaluates expression 2, ..., and evaluates expression n
* The comma operator is also an operator, so it also has an operation result. The value of the entire comma-expression is the value of the last expression
int a = 2;int b = 0;int c;c = (++a, a *= 2, B = A * 5);p rintf ("c =%d", c);
The result of ++a is 3,a *= 2 results for 6,b = A * 5 result is 30. As a result, the output is: c = 30
It is important to note that the right expression is wrapped in parentheses (), if not enclosed in parentheses, that is:
c = ++a, a *= 2, b = A * 5;printf ("c =%d", c);
The output will be: c = 3, because C = ++a is also part of the comma expression and is independent of the subsequent a *= 2 and B = A * 5
"Learning note", "C language" comma operator