ProgrammingVery hardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned short p = 1;
    for (int i = 0; i < 20; i++)
        p *= 2;
    printf("%d", p);
}
  1. A. 1
  2. B. 16
  3. C. 0
  4. D. 65536

Correct answer: C. 0

Each doubling is stored back into an unsigned short, so after 16 doublings the bit has shifted out and p stays 0 from then on.

More C Programming questions

Exams that ask this topic