The comma operator evaluates both of its operands and returns the value of the second operand.
Syntax
expr1, expr2
Parameters
Parameter | Description |
---|---|
expr1, expr2 | Any expressions |
Description
You can use the comma operator when you want to include multiple expressions in a location that requires a single expression. The most common usage of this operator is to supply multiple parameters in a for loop.
For example, if a is a 2-dimensional array with 10 elements on a side, the following code uses the comma operator to increment two variables at once. The code gets the values of the diagonal elements in the array: