Question: I need some help understanding why the following code compiles the way it does. These were questions that I recently had on test. The point

I need some help understanding why the following code compiles the way it does. These were questions that I recently had on test. The point of this test was to see our knowledge of "braces" locations within the code. So this code is missing braces.

1. What is the value after the following code executes?

int (donuts = 10;

if (donuts!= 10)

donuts = 0;

else

donuts += 2;

Answers:

A. 12

B. 10

C. 0

D. 2

I know the answer is 'A', but I am not clear on why. A similar question is posted below.

2. What is the value of donuts after the following code executes?

int donuts = 10;

if (donuts = 1)

donuts = 0;

else

donuts +=2;

Answers:

A. 12

B. 10

C. 0

D. 1

This answer is 'C', but again I am not clear on why.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!