ProgrammingModerateTCS NQT · Wipro

What is printed? Assume unsigned short is 16 bits and int is 32 bits.

What is printed? Assume unsigned short is 16 bits and int is 32 bits.
#include <stdio.h>
int main(void) {
    printf("%d", (unsigned short)(0xFFFF + 1));
}
  1. A. 65536
  2. B. 0
  3. C. 65535
  4. D. 1

Correct answer: B. 0

0xFFFF + 1 is 65536 in int, and conversion to a 16-bit unsigned type reduces it modulo 65536 to 0.

More C Programming questions

Exams that ask this topic