Originally posted by fengqiao cao:
hi there,
int i=10,j=3,k=7
int p=30
what is the vaule of i,j,k,p after the execution of the following
line:
p+=k-=j<<=i%=4
i know first: p+=(k-=(j<<=(i%=4)))
second : p+=(k-=(j<<=(i=2)))
third; p+=(k-=(j<<=2))
fourth p+=(k-=(j=0))
........
when arrived fourth, i don't understand why j=12(the answer provided)?
could someone explain to me?
thanks in adv...
Hi associativity ops (op=) work from Right to Left so there are a couple of steps in the equation:
1. 10 % 4 = 2
2. 3 <<= 2 = 0011 << evaluate and assign 2 places left = 1100 (in binary - i've left off the rest of the 0s) converting this back gives 12
I think in terms that in each position the bits are placeholders for decimals 8421 so for the 1100 bits there is 1 bit in position 8 and one bit in postion 4 this gives 12 (not really scientific but it works for me
all the best - Jim