cout overloads the '<<' operator to print the values. So when you are doing
cout <<1<<20;
It actually prints 1 and 20 and doesnt do any shifting
int shifted = 1 << 20;
cout << shifted;
This should return the same output as python's
simpler way is to do
cout << (1 <<20);
cout << (1<<20);. You're not bit shifting, you're just sending '1' and '20' to cout. You're mixing the output operator and the bit shift operator.cout << (1<<20);. C++ is a context sensitive language. The same symbols mean different things in different contexts (and can even be overloaded to gain entirely new, user-defined, meaning)int.