ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned x = 0xABCD, p = 0;
    while (x) { p ^= x & 1u; x >>= 1; }
    /* p is the parity of the set bits of 0xABCD */
    printf("%u", p);
}
  1. A. 1
  2. B. 0
  3. C. 10
  4. D. 2

Correct answer: B. 0

0xABCD has 2 + 3 + 2 + 3 = 10 set bits, and XORing each bit into p leaves the parity of that count, which is 0.

More C Programming questions

Exams that ask this topic