Can someone explain the following piece of code
int x = 45;
int y = x &= 34;
It assigns 32 to y
It's performing a bitwise "and" as a compound assignment operator. It's equivalent to:
int x = 45;
x = x & 34;
int y = x;
Now 45 = 32 + 8 + 4 + 1, and 34 = 32 + 2, so the result of a bitwise "and" is 32.
Personally I think that using a compound assignment operator in a variable declaration is pretty unreadable - but presumably this wasn't "real" code to start with...
It's a bitwise operation, more information can be found here:
http://msdn.microsoft.com/en-us/library/sbf85k1c%28VS.80%29.aspx
It is equivalent to:
int x = 45;
x = x & 34;
int y = x;
The & operator for integral types computes the logical bitwise AND of its operands.