Transferred from: https://zhidao.baidu.com/question/106961628.html
The syntax for a comma expression is:
Expression 1, expression 2, ... Expression n
C + + order evaluates expression 1, expression 2, ..., value of expression N. For example:
int a,b,c;
A=l,b=a+2, c=b+3;
Because it is evaluated sequentially, it is guaranteed that B must be assigned after a, and C must be assigned after B. The comma expression can be represented by the following 3 ordered assignment statements:
A=1;
b=a+2;
c=b+3;
A comma expression is a value, which is not a substitute for a statement. The value of the comma expression is the value of the nth subexpression, which is the value of the expression N. For example:
int a,b,c,d;
D= (a=1,b=a+2,c=b+3);
cout<<d<<endl;
The output is:
6
The result of the output in the above example is the value of C.
A comma expression can also be used for parameters in a function call. For example:
Func (n, (j=1,j+4), k);
The function call has 3 arguments, and the middle argument is a comma expression. Parentheses are required, otherwise, the function has 4 parameters. The comma expression, as a value, can be used in almost all places.
In C + +, if the last expression of a comma expression is an lvalue, the comma expression is an lvalue. For example:
(a=1,b,c+1,d) =5;//ok: d=5
In C, a comma expression cannot be left-valued, so "(a=1,b,c+1,d) = 5;" will not compile
C + + comma-expression