int main()
{
int i=3;
(i << 1);
cout << i; //Prints 3
}
I expected to get 6 because of shifting left one bit. Why does it not work?
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 bit shift operators return a value.
You want this:
The shift operators don’t shift “in place”. You might be thinking of the other version. If they did, like a lot of other C++ binary operators, then we’d have very bad things happen.