ProgrammingVery hardCompetitive coding (CP)
What is printed? Assume uint32t is 32 bits.
What is printed? Assume uint32_t is 32 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint32_t h = 5381;
const char *s = "ab";
for (; *s; s++)
h = h * 33u + (unsigned char)*s;
printf("%u", h);
}- A. 5863208
- B. 5863207
- C. 177670
- D. 5863216
Correct answer: A. 5863208
The djb2 update h = 33h + c runs over a and b: 5381 * 33 + 97 = 177670, then 177670 * 33 + 98 = 5863208. The value stays inside 32 bits, so there is no wrap-around.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> struct R { int a, b; }; int cmp(const void p, const void q) { const struct R x =…
- How many values of n in 1..50 have bit 2 set (the value 4)? Compute with this program. c #include <stdio.h> int main(void) { int c = 0…
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int m[4][5]; printf("%zu %zu", sizeof m / sizeof m[0]…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned s = 0; for (unsigned i = 1; i <= 100000…
- How many partitions of 5 are there? The program counts partitions of n into parts of size at most m. Compute with it. c #include <stdio.h>…
- What is printed? c #include <stdio.h> int main(void) { char c = 'A'; c += 32; printf("%c %d", c, c); }