ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int t[256];
int main(void) {
    for (int i = 1; i < 256; i++) t[i] = t[i >> 1] + (i & 1);
    printf("%d %d", t[200], t[255]);
}
  1. A. 4 8
  2. B. 3 7
  3. C. 2 8
  4. D. 3 8

Correct answer: D. 3 8

t[i] stores the popcount of i, built from the popcount of i >> 1 plus the low bit. 200 = 11001000 has three set bits, and 255 has eight.

More C Programming questions

Exams that ask this topic