go to previous page   go to home page   go to next page hear noise highlighting

Answer:

24 / 2  - 8
------
  12    - 8
  ---------
       4

Evaluate Equal Precedence from Left to Right

When there are two (or more) operators of equal precedence, evaluate the expression from left to right.


2 * 7 * 3 
-----
  14  * 3
  -------
     42

Since both operators are *, each has equal precedence, so calculate 2 * 7 first, then use that result with the second operator.

Here is a second example:


4 - 2 + 5
-----
  2   + 5
  -------
      7

Now the operators are different, but they both have the same precedence, so they are evaluated left to right.

Usually it doesn't matter if evaluation is done left to right or in any other order. In algebra it makes no difference. But with floating point math it sometimes makes an important difference. Also, when an expression uses a method it can make a very big difference. (Methods are discussed in part 6 of these notes.)


QUESTION 24:

What is the value of the following expression?

2 + 4/2 + 1

go to previous page   go to home page   go to next page