ProgrammingHardGATE CS · TCS NQT

What is printed? Assume unsigned int is 32 bits.

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

Correct answer: A. 4294967294

(unsigned)-1 is 4294967295, and multiplying by 2 wraps modulo 2^32 to 4294967294. The signed value -2 is not a valid unsigned result.

More C Programming questions

Exams that ask this topic