Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions