posted 20 years ago
Given a variable x of type int(can be -ve), which are correct ways of doubling the value of x?
a)x<<1
b)x=x*2;
c)x*=2;
d)x+=x;
e)x<<=1;
Ans given is:b,c,d,e
I thought it is e because multiplication and addition of -ve number does not result in doubling the result here.
Eg: x=-2;x=-2*2=-4<-2
Thanks in advance