170k views
0 votes
What is the value of donuts after the following statement executes?

int donuts = 10;
if (donuts != 10)
donuts = 0;
else
donuts += 2;
a. 12
b. 10
c. 0
d. 1
e. None of these

User Dymv
by
7.9k points

1 Answer

2 votes

Final answer:

After the statement executes, the value of the 'donuts' variable is 12, as the variable initially set to 10 is incremented by 2 in the else branch of the conditional statement.

Step-by-step explanation:

In this programming scenario, we are given a block of code that manipulates an integer variable named donuts. Initially, donuts is set to 10. Then, a conditional statement checks if donuts is not equal to 10. If donuts were not equal to 10, its value would be set to 0. However, since donuts is equal to 10, the else branch of the conditional statement is executed, and donuts is increased by 2, making its new value 12. Therefore, after the statement executes, the value of donuts is 12.

The value of donuts after the statement executes is 12.

User Noureddine AMRI
by
7.8k points