ProgrammingHardProduct company OA
What is printed?
What is printed?
int hs(unsigned n) { return n ? (n & 0xF) + hs(n >> 4) : 0; }
int main(void) { printf("%d", hs(0xBEEF)); }- A. 15
- B. 48
- C. 4
- D. 54
Correct answer: D. 54
n & 0xF is the lowest hex digit and n >> 4 drops it, so hs sums the hex digits: B + E + E + F = 11 + 14 + 14 + 15 = 54. '4' counts the digits instead of adding them.
More C Programming questions
- How many swaps does this bubble sort make? c int a[] = {3, 1, 4, 1, 5}, sw = 0; for (int i = 0; i < 5; i++) for (int j = 0; j < 4 - i…
- What is printed? c printf("%d %d", strncmp("abc", "abd", 2) == 0, strncmp("ab", "ab0x", 5) == 0);
- uint8t a = 200, b = 100; uint8t c = a + b; What is the value of c?
- With uint32t x = 5u - 7u; what is the value of x?
- uint32t x = 0x00F0A8u; what is x & (0u - x) in hexadecimal?
- uint32t n = 0xB6u; the loop while (n) { n &= n - 1; count++; } runs with count starting at 0. What is count when the loop ends?