-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.24.txt
More file actions
8 lines (6 loc) · 985 Bytes
/
4.24.txt
File metadata and controls
8 lines (6 loc) · 985 Bytes
1
2
3
4
5
6
7
8
Our program that distinguished between high pass, pass, and fail de-
pended on the fact that the conditional operator is right associative. Describe how that
operator would be evaluated if the operator were left associative.
finalgrade = (grade > 90) ? "high pass" : (grade < 60) ? "fail" : "pass";
if the operator was left associative, then it would look at whether grade was greater than 90, if it was true, would have returned "high pass", else it would have computed the bool value of the (grade < 60) expression, and only then would have the other operator looked at the returned value of the left hand operator to determine if the left hand operator's returned value is true, in that case returns "fail", or false, when that return "pass"
the character literal (const char *) can be converted to bool, so the first conditional operator would return true if grade were greater than 90, and would return the (grade < 60) expression's value when grade is less than or equal to 90