ProgrammingHardTCS NQT · Infosys

Assume unsigned int is 32 bits. What is printed?

Assume unsigned int is 32 bits. What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t a = 70000, b = 70000;
    uint32_t p = a * b;
    printf("%u", p);
}
  1. A. 605032703
  2. B. 4900000000
  3. C. 3689934592
  4. D. 605032704

Correct answer: D. 605032704

70000 * 70000 = 4900000000, and unsigned arithmetic reduces it modulo 2^32, giving 4900000000 - 4294967296 = 605032704. Subtracting from 2^32 instead of reducing gives 3689934592.

More C Programming questions

Exams that ask this topic