If x = 1, y = 3, z = 0, the value of x, y, and z after executing the following c
ID: 659496 • Letter: I
Question
If x = 1, y = 3, z = 0, the value of x, y, and z after executing the following code fragment is x = 2, y = 3, z = 0.
switch ( x )
{ case 0 : x = 2 ;
y = 3 ;
break ;
case 1 : x = 4 ;
break ;
default : y = 3 ;
x = 1 ;
}
True
False
________________
If x = 0, y = 5, z = 5, what is the value of x, y, and z after executing the following code fragment?
if (x == 0)
{ x = x - 3 ;
z = z + 3 ;
}
else
y = 99 ;
Choose one answer:
a)x = 0, y = 99, z = 5
b)x = -3, y = 5, z = 8
c)x = -3, y = 5, z = 5
d)x = -3, y = 99, z = 8
a)x = 0, y = 99, z = 5
b)x = -3, y = 5, z = 8
c)x = -3, y = 5, z = 5
d)x = -3, y = 99, z = 8
Explanation / Answer
If x = 1, y = 3, z = 0, the value of x, y, and z after executing the following code fragment is x = 2, y = 3, z = 0.
switch ( x )
{
case 0 : x = 2 ;
y = 3 ;
break ;
case 1 : x = 4 ;
break ;
default : y = 3 ;
x = 1 ;
}
False
since initially x= 1 case 1 of switch statement will be executed which assigns x = 4;
so after executing switch statement, x = 4, y = 3, z = 0.
If x = 0, y = 5, z = 5, what is the value of x, y, and z after executing the following code fragment?
if (x == 0)
{ x = x - 3 ;
z = z + 3 ;
}
else
y = 99 ;
since, initially x = 0, if statement will be executed which assigns x = 0-3 = -3 and z = 5+3 = 8
so correct answer is
b)x = -3, y = 5, z = 8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.