ProgrammingHardTCS NQT · Infosys

What is printed? Assume unsigned int is 32 bits.

What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
    unsigned x = 12;
    printf("%u", (x << 3) + (x << 1));
}
  1. A. 118
  2. B. 120
  3. C. 96
  4. D. 132

Correct answer: B. 120

x << 3 is 8x and x << 1 is 2x, so the sum is 10x = 120 for x = 12. 96 forgets the second term, and 132 uses 11x.

More C Programming questions

Exams that ask this topic