ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned h = 0;
    for (const char *s = "abcdefgh"; *s; s++)
        h = (h << 5) ^ (unsigned char)*s;
    printf("%u", h);
}
  1. A. 1081283720
  2. B. 1081283721
  3. C. 1081283728
  4. D. 2147483648

Correct answer: A. 1081283720

Each step shifts the unsigned hash left by five bits and XORs in the next character. The shifts wrap modulo 2^32, so the final value is 1081283720.

More C Programming questions

Exams that ask this topic