Why doesn't left bit-shift, “<<”, for 32-bit integers work as expected when used more than 32 times?
问题 When I write the following program and use the GNU C++ compiler, the output is 1 which I think is due to the rotation operation performed by the compiler. #include <iostream> int main() { int a = 1; std::cout << (a << 32) << std::endl; return 0; } But logically, as it\'s said that the bits are lost if they overflow the bit width, the output should be 0. What is happening? The code is on ideone, http://ideone.com/VPTwj. 回答1: This is caused due to a combination of an undefined behaviour in C