🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Bitwise Operators in C: all 15 questions

Quiz: Bitwise Operators in C · Question 4 of 15

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    unsigned n = 29;
    int c = 0;
    while (n) { n &= n - 1; c++; }
    printf("%d", c);
    return 0;
}
  1. A.4
  2. B.3
  3. C.5
  4. D.29
Answer & explanation

Correct answer: 4

29 is 11101, which has four 1s; each pass removes one.

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 →