ProgrammingHard
unsigned int h = 0; for (const char *p = "ab"; *p; p++) h = h * 31 + *p; printf("%u", h); What is printed (ASCII, 32-bit unsigned)?
- A. 3105
- B. 3104
- C. 3106
- D. 6200
Correct answer: A. 3105
h becomes 97 after 'a' and 97 x 31 + 98 = 3105 after 'b'. No wrap happens at this size.
More C Programming questions
- unsigned int x = 0b11011010; printf("%u", (x >> 3) & 7); What is printed?
- With 32-bit unsigned arithmetic, what does (unsigned)-5 >> 1 print?
- What is the value of ~5 & 0xF in C, with int of 32 bits?
- What is the value of (3 ^ 5) & ~1 in C?
- What is printed by printf("%d", 7 13 % 5 3 % 4);?
- In C99, what are the values of -8 % 3 and 8 % -3?