Q:

Our program that distinguished between high pass, pass, and fail depended on the fact that the conditional operator is right associative

0

 Our program that distinguished between high pass, pass, and fail depended on the fact that the conditional operator is right associative. Describe how that operator would be evaluated if the operator were left associative.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

If the operator were left associative, then the expression

    grade > 90 ? "high pass"
               : grade < 60 ? "fail" : "pass";

would be evaluated as:

    (grade > 90 ? "high pass" : grade < 60) ? "fail" : "pass";

which means:

  - if the grade is greater than 90, then return "high pass", which is not empty string and evaluate to `true`, then return "fail";

  - else evaluates `grade < 60` and takes the result as the condition for the second conditional operator, which means if the grade is less than 60, return "fail", else return "pass".

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now