Practice question · Put in order
Order the evaluation steps of the expression 2 + 3 * (8 - 6) / 2.
- Multiply: 3 * 2 = 6
- Evaluate the parentheses: 8 - 6 = 2
- Divide: 6 / 2 = 3
- Add: 2 + 3 = 5
Hints
- Parentheses first, then the tighter-binding operators, then the looser ones.
- Multiplication and division share a precedence level, so they run left to right.
Show the answer
- Evaluate the parentheses: 8 - 6 = 2
- Multiply: 3 * 2 = 6
- Divide: 6 / 2 = 3
- Add: 2 + 3 = 5
Why
The value is 5. Because * and / bind equally, the multiplication is done before the division simply by position; had you divided first the answer would be unchanged here, but with integer division it would not be.
Practise Variables, Types, and Expressions
The app has 4 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Variables, Types, and Expressions
- In most languages 0.1 + 0.2 == 0.3 evaluates to false. Why do experienced programmers compare floats with a…
- Match each data type to its defining property.
- Select every statement that is TRUE.
- Because a float stores only finitely many digits, two computations that are mathematically equal can produce…
- In mathematics x = x + 1 is a contradiction with no solution. In most programming languages it is a routine…
- The symbol + adds numbers but joins text. Sort each expression by what + actually does.