ProgrammingHardTCS NQT · Wipro

What is printed? Assume uint16t is 16 bits.

What is printed? Assume uint16_t is 16 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint16_t x = 60000;
    uint16_t y = x * 2;
    printf("%d", y);
}
  1. A. 120000
  2. B. -11072
  3. C. 55000
  4. D. 54464

Correct answer: D. 54464

x * 2 is 120000 in int, and storing it in uint16_t keeps 120000 mod 65536 = 54464. The signed reading -11072 comes from treating the 16-bit pattern as two's complement.

More C Programming questions

Exams that ask this topic