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)?

  1. A. 3105
  2. B. 3104
  3. C. 3106
  4. 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

Exams that ask this topic