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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started