← Quiz: Bitwise Operators in C: all 15 questions
Quiz: Bitwise Operators in C · Question 11 of 15
What does this print? (code)
What does this print?
#include <stdio.h>
int main(void) {
int n = 29, count = 0;
while (n) {
n &= n - 1;
count++;
}
printf("%d\n", count);
return 0;
}
- A.5
- B.4
- C.3
- D.29
Answer & explanation
Correct answer: 4
29 is 11101 in binary. Each n &= n - 1 removes the lowest set bit, so the loop runs once per 1-bit: 4 times.
Can you get the rest right without peeking?
Take the timed Quiz: Bitwise Operators in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →