Assuming all variables in the following code fragments are t
Assuming all variables in the following code fragments are type int, what are the values of x, y, & z after each of the code fragments are executed? x = y = z = 1; x = (x--, y++, 2*y+z); x = ___ y = ___ z = ____ x = y = z = 1; if (x >2) y=2; else y=4; x = ___ y = ___ z = ___ x = 1; y = 5; z = 3; x = (y0) && (y--
Solution
Answer:
a) x = y = z = 1 ;
x = 1 , y = 2 , z = 3 Here x -- is post decremented means x is assigned the value then it is decremented, Y++ it is post incremented , here y is assigned to x after that it is incremented by 1.
b) x = y = z = 1 , x > =2 ( nO ) , y = 4 , z =1
Since there is only one condition x > 2 , hence it is false we goto else statement where y = 4
c) y = 5 , x = 1 , z = 3
x = 9 , y = 5 , z =3 , since (y<0) is false we operate ++y+z
