The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if

  • 0 replies
  • 1904 views
*

Offline mechanic

  • *****
  • 2565
    • View Profile
    • Engineering Forum
The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if
« on: February 26, 2017, 08:09:34 PM »
Question: The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if

Options are:


A. - is left associative and * has precedence over -
B. - is right associative and * has precedence over -
C. - is right associative and - has precedence over *
D. - is left associative and - has precedence over *

Correct answer is:

C. - is right associative and - has precedence over *

Explanation:

5 - 2 - 3 * 5 - 2 will yield 18, if it is treated as (5-(2-3))*(5-2). ie.  if - has precedence over * and if it associates from the right.