ProgrammingModerateProduct-company MCQ pattern

On a two's-complement machine, what is printed?

On a two's-complement machine, what is printed?
printf("%d %d", 40 & -40, 40 & (40 - 1));
  1. A. 32 8
  2. B. 40 0
  3. C. 8 39
  4. D. 8 32

Correct answer: D. 8 32

40 = 101000. -40 is ~40 + 1, which keeps only the lowest set bit in common: 40 & -40 = 1000 = 8. 40 & 39 = 101000 & 100111 = 100000 = 32, which clears the lowest set bit.

More C Programming questions

Exams that ask this topic