[CSI] Old final exam review

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Feb 27 11:07:26 EST 2019


> 
> In the answer of question number 7 of the old final exam we used
> parentheses in the conditional operator. when I tried it in visual studio
> without parentheses is did not work. my question is why do we have to use
> parentheses in this case?
> 
> cout << (found ? "FOUND" : "NOT FOUND");

The precedence (order of execution) of insertion operator is higher
than that of the conditional assignment so this code

is equivalent to

  (cout << found) ? "FOUND" : "NOT FOUND"

which is not legal because (cout << found) is not a boolean
expression.


thanks,
--
Mikhail


More information about the cs13001 mailing list