ProgrammingVery hardGATE CS · Campus placements

uint16_t h = 0; for each character c of "ABCDE", h = h * 31 + c; with 65 for 'A' and so on. What is h at the end?

  1. A. 64579
  2. B. 65535
  3. C. 2081
  4. D. 64580

Correct answer: A. 64579

The multiply and add are done in int and then stored in uint16_t, which reduces modulo 65536 at each step. The final value is 64579. Stopping after "AB" would give 2081.

More C Programming questions

Exams that ask this topic