Evaluate each of the following expressions and give the valu

Evaluate each of the following expressions, and give the value of any variable used in the expression after the expression is executed. For each instruction assume the variables are given the following values. X=3; y=5; z=7; If a variable changes in one expression, assume it is reset to its original value before performing any later expressions (i.e., x is 3 at the beginning of each expression). The first is done as an example. Show the steps used to get your result.

Solution

x=3,y=5,z=7
a.
x+=y*=z^=x
^=EXOR
z=z^x=0111 EXOR 0011=0100=4
x+=(y*=4)==>y=y*4=20
x+=20==>x=x+20
x=23,y=5,z=7
b.
z>>=y>>=x==2
>> right shift i.e left operands are shifted right by given bits.
x==2 is condition checking hece retrns boolean,here consider false=0,true =1;x==2 is false i.e 0
as it is 0,no movei.e y>>0=5
z>>=y ==>z=z>>y ==>7 right shift by 5 bits
as 7 has 4 bits only 0111 by 5 bits resuts to 0.
c.
x=y==z==y
here z is not equal to y thus return 0
y is not equal to 0 thus 0
x=y==?=>x=0

x=0,y=5,z=7

d.
x^=y|=z&=10
& (bitwise and)
|(bitwise OR)
First z=Z bitwise & 10= 0111 bitwise & 1010 ==>0010 =2
Now y=y|2
y bitwise OR 2 ==>0101 bitwise | 0010 ==>0111-7
Now x=x EXOR 7==>0011 EXOR 0111 ==>0100=4
So x=4,y=5,z=7;

e.
z+=y+=++x
z+=y+=4
z+=y+4==>z+=5+4
z=z+9=14

So Z=14
x=4,y=5

f.
z*=y=x+=1
z*=y=4
z=z*y=7*4=28

so z=28,y=5,x=3;

g.
z%=x-=--y-3
z%=x-=(--y)-3==x-=4-3
z%=x-=1
z%=x=x-1=2
z%=2==>z=z%2
z=7%2 =1
z=1,y=4,x=3

 Evaluate each of the following expressions, and give the value of any variable used in the expression after the expression is executed. For each instruction as
 Evaluate each of the following expressions, and give the value of any variable used in the expression after the expression is executed. For each instruction as

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site