ProgrammingVery hardGATE CS · Competitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int c = 0;
    for (unsigned x = 0; x < 256; x++)
        if ((x & (x >> 1)) == 0) c++;
    printf("%d", c);
}
  1. A. 55
  2. B. 89
  3. C. 34
  4. D. 56

Correct answer: A. 55

Counting 8-bit strings with no two adjacent set bits gives the Fibonacci number F(10) = 55. Using F(9) = 34 or the next value 89 are the usual off-by-one slips.

More C Programming questions

Exams that ask this topic