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?
- A. 64579
- B. 65535
- C. 2081
- 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
- Which function correctly tests whether an unsigned value x is a power of two, with x = 0 excluded?
- char b[6]; snprintf(b, sizeof b, "%s-%d", "abcdef", 12345); int r = snprintf(NULL, 0, "%s-%d", "abcdef", 12345); printf("%s %d", b, r)…
- char b[5]; / stdin holds the nine bytes: abcdefgh and a newline / int calls = 0; do { fgets(b, sizeof b, stdin); calls++; } while…
- char s[] = "a,,b,c"; int n = 0; for (char t = strtok(s, ","); t != NULL; t = strtok(NULL, ",")) n++; printf("%d", n); What is printed?
- char d[8] = "ab"; strncat(d, "cdefgh", 3); printf("%zu", strlen(d)); What is printed?
- Which statement about the value returned by strcmp("apple", "Apple") is guaranteed by the C standard?