ProgrammingVery hardProduct company OA · GATE CS

With a 32-bit unsigned int x, which expression has undefined behaviour?

  1. A. (x << 16) << 16
  2. B. x << 32
  3. C. x << 0
  4. D. x >> 31

Correct answer: B. x << 32

Shifting by a count greater than or equal to the width of the (promoted) type is undefined, even for unsigned values; on x86 x << 32 often gives x unchanged rather than 0. Two shifts of 16 are each legal and give 0.

More C Programming questions

Exams that ask this topic