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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the
&operator is evaluated after the+operator and3 & 0equals0.Of course you can place braces around the expressions to change the evaluation order. E.g: