ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
int n = 40;          /* binary 101000 */
printf("%d %d %d", n & (n - 1), n & -n, (n & (n - 1)) == 0);
  1. A. 32 8 1
  2. B. 39 8 0
  3. C. 32 40 0
  4. D. 32 8 0

Correct answer: D. 32 8 0

n − 1 = 100111, so n & (n − 1) clears the lowest set bit: 100000 = 32. n & −n keeps only the lowest set bit: 8. The result is 0 only for powers of two, so the test prints 0 for 40.

More C Programming questions

Exams that ask this topic