ProgrammingHardIBM · Deloitte pattern

What is printed?

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

Correct answer: C. -4 -4

~a + 1 is exactly the two's-complement negation formula: ~4 = -5, +1 = -4, which equals -a (-4) — confirming the identity ~x + 1 == -x. Both expressions print -4.

More C Programming questions

Exams that ask this topic