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

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

1 Answer

3 votes

Final answer:

The value of the variable donuts after executing the given code is 12.

Step-by-step explanation:

The value of donuts after the given code executes can be determined by examining the code step by step:

  1. Initialize donuts with a value of 10.
  2. Check if the condition (donuts = 1) is true. Since it is not, move to the else block.
  3. In the else block, the value of donuts is incremented by 2, resulting in a value of 12.

Therefore, the value of donuts after the code executes is 12.

User Ricardo Parker
by
7.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.