ProgrammingVery hardTCS NQT · Infosys

Assume uint16t and int are 16 and 32 bits. What is printed?

Assume uint16_t and int are 16 and 32 bits. What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint16_t a = 40000, b = 3;
    int p = a * b;
    uint16_t q = a * b;
    printf("%d %d", p, q);
}
  1. A. 120000 65535
  2. B. -5536 54464
  3. C. 120000 54464
  4. D. 54464 54464

Correct answer: C. 120000 54464

a and b are promoted to int, so the product 120000 fits and is stored in p unchanged. Converting it to uint16_t gives 120000 mod 65536 = 54464.

More C Programming questions

Exams that ask this topic