ProgrammingModerateTCS NQT · Infosys

What is printed? Assume a 32-bit unsigned int.

What is printed? Assume a 32-bit unsigned int.
#include <stdio.h>
int main(void) {
    unsigned x = 1;
    for (int i = 0; i < 31; i++) x <<= 1;
    printf("%u", x);
}
  1. A. 1073741824
  2. B. 2147483648
  3. C. 4294967295
  4. D. 2147483647

Correct answer: B. 2147483648

Shifting 1 left 31 times gives 2^31 = 2147483648, which fits in unsigned int without wrap.

More C Programming questions

Exams that ask this topic