ProgrammingHardTCS NQT · Infosys

What is printed? Assume unsigned short is 16 bits.

What is printed? Assume unsigned short is 16 bits.
#include <stdio.h>
int main(void) {
    unsigned short a = 255, b = 255;
    unsigned c = a * b;
    printf("%u", c);
}
  1. A. 65535
  2. B. 255
  3. C. 64770
  4. D. 65025

Correct answer: D. 65025

Both operands promote to int, the product 65025 fits in int, and the result is stored in unsigned without change.

More C Programming questions

Exams that ask this topic