In VC2008, I typed this code:
int a = 2 + 1 & 0;
and this expression's result is a = 0
Why the result is 0 but not 2?
Because the &
operator is evaluated after the +
operator and 3 & 0
equals 0
.
Of course you can place braces around the expressions to change the evaluation order. E.g:
int a = 2 + (1 & 0);
/* a == 2 */
The +
has greater precedence than the &
. Here is a complete table of operator precedence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With