ProgrammingModerateTCS NQT · Infosys

Assume int and unsigned int are 32-bit. What does this program print? #include <stdio.h> int main(void) { unsigned int a = 3; int b = -5; if (a + b > 0) printf("P"); else printf("N"); printf("%d", (int)(a + b)); return 0; }

  1. A. N-2
  2. B. P4294967294
  3. C. N2
  4. D. P-2

Correct answer: D. P-2

b is converted to unsigned, so a + b is the unsigned value 4294967294, which is greater than 0 and prints P. Converting it back to int gives -2.

More C Programming questions

Exams that ask this topic