ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int x = 10;
    printf("%d %d", x & -x, x & (x - 1));
}
  1. A. 2 8
  2. B. 2 10
  3. C. 8 2
  4. D. 4 8

Correct answer: A. 2 8

x & -x keeps the lowest set bit of 1010, which is 2, and x & (x - 1) clears that bit, leaving 1000 = 8.

More C Programming questions

Exams that ask this topic