ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned a = 3;
    int b = -5;
    printf("%d", (a + b) > 0);
}
  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: A. 1

b becomes the unsigned value 2^32 - 5, so a + b wraps to 2^32 - 2, which is greater than 0.

More C Programming questions

Exams that ask this topic