Alex Rivera | Logout

Why hasn't my variable changed after applying a bit-shift operator to it?

Asked 2011-06-16T05:14:29.543
11
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?

Edit
Report

1 Answer

10

You should use <<= or the value is just lost.

answered 2011-06-16T05:16:34.687

Your Answer