pointers-memory · intermediate · ~15 min
Bit-level loops; the n &= (n-1) trick.
Implement int popcount(unsigned int n) returning the number of 1-bits in n.
int popcount(unsigned int n) { /* TODO */ return 0; }
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.