ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned x = 0xB, p = 0;
    for (; x; x &= x - 1) p ^= 1;
    printf("%u", p);
}
  1. A. 0
  2. B. 3
  3. C. 1
  4. D. 2

Correct answer: C. 1

0xB = 1011 has three set bits, and XORing 1 for each one leaves the parity 1.

More C Programming questions

Exams that ask this topic