Jul 01
  • Parenthesis are at the highest level of precedence. In case of nested parenthesis,the innermost parenthesis are evaluated first.

Example

(((3+4)*5)/6)

3+ 4                             step 1

7 * 5                             step 2

35 / 6                           step 3

  • Multiplication, division & modulus are evaluated next. If an expression contains several multiplication,division and modulud operators,evaluation precedes from left to right, These three are at same level of precedence.

Example

5 * 5 + 6 *7

5 * 5                            step 1

6 * 7                            step 2

25 + 42                       step 3

Example:

7*2/2%4

7 *2                              step 1

14/2                             step 2

7%4                              step 3

  • Addition,subtraction  are evaluated last.

Example:

z = 3+ 8 * 7  /4 % 2 – 1

order :  *  /  %  +  -  =

therefore it is evaluated as

  1. 3+ 8 * 7 /4 % 2 -1
  2. 3 + 56/4 % 2 -1
  3. 3 + 14 % 2 – 1
  4. 3 + 0 -1
  5. 3-1
  6. z = 2.

written by Shweta \\ tags: