Author Topic: The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if  (Read 2096 times)

Offline mechanic

The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if
« on: February 26, 2017, 08:09:34 PM »
Advertisement
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.

Engineering Forum

The expression 5 - 2 - 3 + 5 - 2 will evaluate to 18, if
« on: February 26, 2017, 08:09:34 PM »