ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int a = 4;
int r = ~a + 1 == -a;
printf("%d", r);
  1. A. 0
  2. B. -5
  3. C. 4
  4. D. 1

Correct answer: D. 1

~ binds tighter than + and ==, so this is ((~a) + 1) == (-a). ~a+1 is exactly the two's-complement negation of a (a known identity), which always equals -a, so the comparison is true (1).

More C Programming questions

Exams that ask this topic