Order of operations and grouping
When an expression contains two or more operators, it is essential to know which operation will be performed first, next, and so on. This is known as the order of evaluation. Not all operations are evaluated from left to right.
Consider 3 + 4 * 5. Does this evaluate to 35 – 3 + 4 = 7 * 5 = 35? Or does this evaluate to 23 – 4 * 5 = 20 + 3 = 23?
If, on the other hand, we explicitly group these operations in the manner desired, we remove all doubt. Either 3 + (4 * 5) or (3 + 4) * 5 is what we actually intend.
C has built-in precedence and associativity of operations that determine how and in what order operations are performed. Precedence determines which operations have a higher priority and are, therefore, performed before those with a lower priority. Associativity refers to how operators of the same precedence are evaluated – from left to right or from right to left.
The following table shows all the operators we have...