ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned short s = 1;
    s <<= 15;
    printf("%d", s);
}
  1. A. 65536
  2. B. 16384
  3. C. 32768
  4. D. 1

Correct answer: C. 32768

Shifting 1 left by 15 gives 2^15 = 32768, which fits in unsigned short. A shift by 16 would not fit and would be wrong here.

More C Programming questions

Exams that ask this topic