The C language provides a special operator-the comma operator. Use it to connect two expressions together. Such as:
3+5,6+8
Called a comma expression, also known as the order evaluation operator. The general form of a comma expression is
Expression 1, Expression 2
The solution to the comma expression is to solve the expression 1 first and then solve the expression 2. The value of the entire comma expression is the value of expression 2. For example, the above comma expression "3+5,6+8" has a value of 14. As another example, a comma-expressionA=3*5,a*4To solve this expression, the reader may have two different understandings: one thinks "3*5,a*4" is a comma expression, the value of this comma expression is first calculated, if the original value of a is 3, then the value of the comma expression is 12, assigns 12 to a, so the last value of a is 12. Another thought: "A=3*5" is an assignment expression "," a*4 "is another expression, the two are concatenated with commas to form a comma expression. Which of the two is right? The assignment operator has a higher precedence than the comma operator, so a=3*5 should be solved first (that is, "a=3*5" as an expression). After calculation and assignment, the value of a is 15, and then the a*4 is solved by 60. The value of the entire comma expression is 60.A comma expression can also form a new comma expression with another expression, such as (A=3*5,A*4), a+5 first calculates that the value of a is equal to 15, then the operation of A*4 is 60 (but the value of a is not changed, still 15), and then A+5 20, that is, the value of the entire expression is 20.The general form of a comma expression can be extended to
Expression 1, expression 2, expression 3 ... Expression n
Its value is the value of the expression N.
The comma operator is the lowest level in all operators. Therefore, the following two expressions function differently:
①x= (a=3,6*3)②x=a=3,6*a
① is an assignment expression that assigns the value of a comma expression to the value of x,x equal to 18. The ② is a comma expression that includes an assignment expression and an arithmetic expression, with the value of x 3.
printf ("%d,%d,%d", a,b,c);
C language expressive ability, one of the important aspects is that its expression type is rich, the operator is strong, so C use flexible, strong adaptability