ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned x = 11, y = x & (x + 1);
    printf("%u", y);
}
  1. A. 11
  2. B. 12
  3. C. 8
  4. D. 0

Correct answer: C. 8

x & (x + 1) clears the trailing run of 1 bits: 11 = 1011 and 12 = 1100, so the AND is 1000 = 8. 12 is just x + 1, and 0 assumes x and x + 1 can share no bits.

More C Programming questions

Exams that ask this topic