Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 13 (1 point) What is y after the following switch statement? int x = 0;

ID: 3859230 • Letter: Q

Question

Question 13 (1 point)

What is y after the following switch statement?
int x = 0;
int y = 0;
switch (x + 1) {
case 0: y = 0;
case 1: y = 1;
default: y = -1
}

Question 13 options:

None of the above

Question 14 (1 point)

Analyze the following code.
int x = 0;
int y = ((x<100) && (x>0)) ? 1: -1;

Question 14 options:

1) 1 2) -1 3) 0

None of the above

Question 14 (1 point)

Analyze the following code.
int x = 0;
int y = ((x<100) && (x>0)) ? 1: -1;

Question 14 options:

1) The code has a syntax error because & must be &&. 2) y becomes 1 after the code is executed. 3) y becomes -1 after the code is executed. 4) None of the above.

Explanation / Answer

Answer for Question 13: 2) -1

explanation: Whenever we use select....case it is necessary to use break; after declaring all statements after case, if we don't follow this the basic working of select....case will be changed and it will be executed one statement after another hence in given program the evaluation of (x+1) will be (0+1)=1 and the case 1: will be executed but as there is no break; statement the program will be continue to run its next line which is y=-1.

Answer for Question 14:

3) y becomes -1 after the code is executed.

Explanation:

If we look at first line int x = 0; this will initialize 0 in x

Now if we look at second line int y = ((x<100) && (x>0)) ? 1: -1; this line used short hand if statement in which the test condition is ((x<100) && (x>0)) now for this if we solve first bracket (x<100) it is true and if we solve second bracket term (x>0) it is false as x is 0. This means that to satisfy && condition both terms result should be true but it is not happening hence result for false condition which is -1 will be stored in y and y becomes -1 after the code is executed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote