You are here

An Expression Example with Evaluation

5 February, 2015 - 14:51

Let's look at an example: 2 + 3 * 4 + 5 is our expression but what does it equal?

  1. the symbols of + meaning addition and * meaning multiplication are our operators
  2. the values 2, 3, 4 and 5 are our operands
  3. precedence says that multiplication is higher than addition
  4. thus, we evaluate the 3 * 4 to get 12
  5. nowwehave:2+12+5
  6. the associativity rules say that addition goes left to right, thus we evaluate the 2 +12 to get 14
  7. nowwehave:14+5
  8. fnally, we evaluate the 14 + 5 to get 19; which is the value of the expression

Parentheses would change the outcome. (2 + 3) * (4 + 5) evaluates to 45.
Parentheses would change the outcome. (2 + 3) * 4 + 5 evaluates to 25.