LESSON 7: OPERATOR PRECEDENCE
Lesson Outcomes
By the end of this lesson, learners will be able to:
- Understand what operator precedence is
- Apply the correct order of operations
- Use BODMAS correctly in calculations
- Avoid errors caused by incorrect operation order
Lesson Overview
In mathematics and programming, calculations often involve multiple operations. If these operations are not performed in the correct order, the result will be incorrect.
Operator precedence defines which operations should be performed first when multiple operators are present in an expression.
This concept is critical in:
- Programming
- Automation workflows
- Mathematical calculations
- Logical expressions
What is Operator Precedence?
Operator precedence determines how expressions are evaluated when more than one operator is present.
Definition
The precedence of an operator specifies how tightly it binds two expressions together.
For example:
1 + 5 × 3 = 16 (not 18)
This is because multiplication has a higher precedence than addition.
Why Operator Precedence is Important
If the order of operations is ignored:
- Calculations become incorrect
- Programs produce wrong outputs
- Automation processes fail
Correct precedence ensures:
- Accurate results
- Logical consistency
- Reliable systems
Order of Operator Precedence
Operations must be performed in the following order:
- Exponentiation (powers, roots)
- Multiplication and Division
- Addition and Subtraction
BODMAS Rule
Operator precedence is commonly remembered using the BODMAS rule:
- B – Brackets
- O – Order (powers/roots)
- D – Division
- M – Multiplication
- A – Addition
- S – Subtraction
How BODMAS Works
When solving expressions:
- Solve brackets first
- Then powers (orders)
- Then division and multiplication (left to right)
- Then addition and subtraction (left to right)
Examples
Example 1
5 + 3 × 2
Step 1: Multiply → 3 × 2 = 6
Step 2: Add → 5 + 6 = 11
Example 2
(5 + 3) × 2
Step 1: Brackets → 5 + 3 = 8
Step 2: Multiply → 8 × 2 = 16
Example 3
10 − 2 × 3
Step 1: Multiply → 2 × 3 = 6
Step 2: Subtract → 10 − 6 = 4
Equal Precedence Rules
When operators have the same level of precedence:
-
Solve from left to right
Example:
10 ÷ 2 × 5
Step 1: 10 ÷ 2 = 5
Step 2: 5 × 5 = 25
Use of Parentheses
Parentheses (brackets) can be used to override precedence.
They force certain calculations to be done first.
Example
Without brackets:
2 + 3 × 4 = 14
With brackets:
(2 + 3) × 4 = 20
Operator Precedence in Programming
In programming languages:
- The same precedence rules apply
- Incorrect ordering can cause bugs
- Expressions must be carefully structured
Example in Programming Logic
result = 10 + 5 * 2
Correct result = 20 (not 30)
Lesson Summary
In this lesson, learners explored:
- The meaning of operator precedence
- The correct order of operations
- The BODMAS rule
- How precedence affects calculations and programming
Understanding operator precedence is essential for accurate calculations and reliable automation systems.