ProgrammingHardGATE CS · TCS NQT

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned x = 1u << 31;
    x <<= 1;
    printf("%u", x);
}
  1. A. 2147483648
  2. B. 0
  3. C. 1
  4. D. 4294967295

Correct answer: B. 0

Shifting the top bit out of an unsigned int leaves 0, since the shift is reduced modulo 2^32.

More C Programming questions

Exams that ask this topic