ProgrammingVery hardTCS NQT · Infosys

What is printed? Assume unsigned int is 32 bits.

What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
    unsigned a = 65536u;
    printf("%u", a * a);
}
  1. A. 1
  2. B. 65536
  3. C. 0
  4. D. 4294967295

Correct answer: C. 0

65536 * 65536 = 2^32, and 32-bit unsigned arithmetic is defined modulo 2^32, so the product wraps to exactly 0. 4294967295 (UINT_MAX) assumes the value clamps at the maximum, which unsigned types never do.

More C Programming questions

Exams that ask this topic