ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
static const unsigned char t[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
unsigned x = 0xF0F0, c = 0;
for (int i = 0; i < 4; i++) {
c += t[x & 0xF];
x >>= 4;
}
printf("%u", c);
}- A. 4
- B. 16
- C. 8
- D. 12
Correct answer: C. 8
The table holds the popcount of each nibble. The nibbles of 0xF0F0 are F, 0, F, 0, whose table values are 4, 0, 4, 0, summing to 8.
More C Programming questions
- How many times does the value change between neighbours in {1, 1, 2, 2, 2, 3, 1}? Compute with this program. c #include <stdio.h> int…
- How many numbers from 1 to 100 are divisible by 4 but not by 3? Compute with this program. c #include <stdio.h> int main(void) { int c =…
- What is printed by this memoised recursion? The static memo table starts with every entry zero, and calls counts each call to f. c…
- What is printed? c #include <stdio.h> int main(void) { int arr[2 3 + 1]; printf("%zu", sizeof arr / sizeof arr[0]); }
- How many paths go from the top-left to the bottom-right of a 3 by 3 grid of points, moving right or down, without passing through the…
- What is printed? c #include <stdio.h> int main(void) { int a = 2147483647; printf("%u", (unsigned)a + 1u); }