187k views
3 votes
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 will not compile because it uses improper syntax
B) The condition does not short circuit causing a division by zero error
C) 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
D) The condition short circuits and the assignment statement is not executed
E) The condition short circuits and the assignment statement is executed without problem

1 Answer

5 votes

Answer:

D) The condition short circuits and the assignment statement is not executed

Step-by-step explanation:

count is 0.

total is 20.

max is 1.

if (count != 0 && total / count > max)

max = total / count;

If count is not zero AND total/count is bigger than max, max is updated.

However, since count is 0, the program will not enter this loop, meaning that the condition will short circuit and the assignement will not be executed.

The correct answer is:

D) The condition short circuits and the assignment statement is not executed

User Vladexologija
by
7.0k points