ProgrammingHardTCS NQT · Infosys

What is printed? Assume int is 32 bits.

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

Correct answer: B. 4294967290

a is converted to unsigned, so a * b is computed modulo 2^32 and gives 2^32 - 6 = 4294967290. The signed value -6 cannot be the result of an unsigned multiplication.

More C Programming questions

Exams that ask this topic