A. TRUE.B. TRUE. NOTE THAT EXPRESSIONS A AND B MEAN EXACTLY THE SAM...

1. a. true.b. true. Note that expressions a and b mean exactly the same thing. Because the operators ==and < have higher precedence than &&, you do not need to include the parentheses. The parentheses do, however, make it easier to read. Most people find the expression in a easier to read than the expression in b, even though they mean the same thing.c. true.d. true.e. false. Since the value of the first subexpression, (count == 1), is false, you know that the entire expression is false without bothering to evaluate the second subexpression. Thus, it does not matter what the values of x and y are. This is short-circuit evaluation.f. true. Since the value of the first subexpression, (count < 10), is true, you know that the entire expression is true without bothering to evaluate the second subexpression. Thus, it does not matter what the values of x and y are. This is short-circuit evaluation.g. false. Notice that the expression in g includes the expression in f as a subexpression. This subexpression is evaluated using short-circuit evaluation as we described for f. The entire expression in g is equivalent to !( (true || (x < y)) && true )which in turn is equivalent to !( true && true ), and that is equivalent to !(true), which is equivalent to the final value of false.h. This expression produces an error when it is evaluated because the first subexpression, ((limit/count) > 7), involves a division by zero.i. true. Since the value of the first subexpression, (limit < 20), is true, you know that the entire expression is true without bothering to evaluate the second subexpression. Thus, the second subexpression,((limit/count) > 7)is never evaluated, and so the fact that it involves a division by zero is never noticed by the computer. This is short-circuit evaluation.j. This expression produces an error when it is evaluated because the first subexpression,

Answers to Self-Test Exercises 85

k. false. Since the value of the first subexpression, (limit < 0), is false, you know that Thus, the second subexpression, ((limit/count) > 7)l. If you think this expression is nonsense, you are correct. The expression has no intuitive meaning, but C++ converts the int values to bool and then evaluates the && and !operations. Thus, C++ will evaluate this mess. Recall that in C++, any nonzero integer converts to true and 0 converts to false, so C++ will evaluate (5 && 7) + (!6)as follows. In the expression (5 && 7), the 5 and 7 convert to true; true && trueevaluates to true, which C++ converts to 1. In the expression (!6) the 6 is converted to true, so !(true) evaluates to false, which C++ converts to 0. Thus, the entire expression evaluates to 1 + 0, which is 1. The final value is thus 1. C++ will convert the number 1 to true, but the answer has little intuitive meaning as true; it is perhaps better to just say the answer is 1. There is no need to become proficient at evaluating these nonsense expressions, but doing a few will help you to understand why the compiler does not give you an error message when you make the mistake of mixing numeric and Boolean operators in a single expression.