Grouping Operators
Grouping operators are useful for controlling the evaluation of an expression.
Parentheses
Expressions can be grouped by using parentheses () and are always evaluated first.
1 +2 * 3 = 7 whereas (1+2) * 3 = 9 |
Conditional operator
A conditional operator ?: can be used to return an argument for a given condition. The second argument is returned if the first argument is True; otherwise the condition returns the third argument. The first argument must be a Boolean or numeric type, and the second and third arguments must be compatible types.
1 == 2 ? 3 : 4 will return 4 since the first argument is false 2 > 1 ? 5 : 6 will return 5 since the first argument is true |
Sequence operator
A sequence operator or comma evaluates first argument, and then second argument, and finally returns the second argument value.
a = 3, 4 + 5 will assign 3 to a, and then returns 9 |