This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Given a variable x of type int(which may contain a negative value) which are correct ways of doubling the value of x,barring any overflow? (a) x << 1; (b) x <<= 1; The answer is (b). Can anybody please explain why?? i thought both are correct. Thanks
Don't know what else you're looking for. Would this help?
Joined: May 02, 2002
Oops!! Forgot the concept that the value of the left-hand operand is NOT affected by the shift operator ,whereas in the second case,x gets the new value due to extended assignment..Yeah I got it!! Thanks a lot for your examples..