Chapter 5 Conditionals and Loops
1) The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as
A) boolean execution
B) conditional statements
C) try and catch
E) flow of control
Explanation: E) The "flow of control" describes the order of execution of instructions. It defaults to being linear (or sequential) but is altered by using control statements like conditionals and loops.
2) Of the following if statements, which one correctly executes three instructions if the condition is true?
A) if (x < 0) a = b * …show more content…
9) Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;
A) The condition short circuits and the assignment statement is not executed
B) The condition short circuits and the assignment statement is executed without problem
C) The condition does not short circuit causing a division by zero error
D) The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error
E) The condition will not compile because it uses improper syntax
Explanation: A) Since count is 0, (count != 0) is false. Because the left-hand side of an && condition is false, the condition is short circuited, and so the right-hand side is not evaluated. Thus, a potential division by zero error is avoided. Because the condition is false, the statement max = total / count is not executed, again avoiding a potential