ProgrammingHard

Which statement about left-shifting a negative signed integer in C is correct?

  1. A. It is undefined behaviour, so shifts of negative signed values must be avoided
  2. B. It always gives the arithmetic result multiplied by two
  3. C. It is defined and gives a positive value
  4. D. It is defined only on two's-complement machines by the standard

Correct answer: A. It is undefined behaviour, so shifts of negative signed values must be avoided

C leaves a left shift of a negative signed value undefined, so code should shift an unsigned copy instead.

More C Programming questions

Exams that ask this topic