[Study Notes] [C Language] comma operator, learning notes comma Operator
The comma operator is mainly used to connect expressions, such:
Int a = 9; int B = 10; a = a + 1, B = 3*4;
* The expression connected by the comma operator is called a comma expression, which generally takes the following form:
Expression 1, expression 2 ,... ..., Expression n
The operation procedure of the comma expression is: from left to right, first calculate expression 1, then calculate expression 2,..., and finally calculate 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 ); printf ("c = % d", c );
+ The result of a is 3, the result of a * = 2 is 6, and the result of B = a * 5 is 30. Therefore, the output result is: c = 30
Note that the expression on the right is enclosed by parentheses:
C = ++ a, a * = 2, B = a * 5; printf ("c = % d", c );
The output result will be: c = 3, because c = ++ a is also part of the comma expression, which is independent of a * = 2 and B = a * 5.