ProgrammingVery hardGATE CS · TCS NQT

Assume unsigned int is 32 bits. What is printed?

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

Correct answer: B. -3 2147483644

Signed division truncates toward zero, so -7 / 2 = -3. The unsigned value 4294967289 divided by 2 gives 2147483644.

More C Programming questions

Exams that ask this topic