Left shifting a number by 1 is always equivalent to multiplying it by 2.
Answer: A
Correct answer: False
The equivalence holds only while the result fits. Left-shifting a signed value whose top bits are significant overflows, and signed overflow is undefined behaviour in C - on a 32-bit int, 0x40000000 << 1 does not give twice that value but a negative number.
Shifting a negative value left is undefined outright. The statement is true when restricted to unsigned types, where the arithmetic is defined to wrap modulo \( 2^n \), which is precisely why the companion question about unsigned int and char answers the other way.
Please log in or register to report this question.