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>
uint32_t rotl(uint32_t x, unsigned k) {
return (x << k) | (x >> ((32 - k) & 31));
}
int main(void) {
printf("%X", (unsigned)rotl(0x80000001u, 4));
}- A. 18
- B. 10
- C. 80000018
- D. 8
Correct answer: A. 18
Rotating 0x80000001 left by 4 moves the top nibble 8 down to the bottom and leaves the low bits 0x10, so the result is 0x18. The mask (32 - k) & 31 avoids a shift by 32, which would be undefined.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned u = 1; int s = -2; printf("%d %d", s < u, s + (int)u > -2); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int i = 1; sizet n = sizeof(i++); printf("%d %zu", i, n); }
- How many factors of 2 does 100! contain? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for (int i = 2; i <=…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "stressed"; char a = s, b = s + 7; while (a < b) {…
- What is printed? c #include <stdio.h> unsigned parse(const char s) { unsigned n = 0; while (s) n = n 10 + (unsigned)(s++ - '0'); return n…
- What is printed? c #include <stdio.h> int main(void) { long long x = (1LL << 40) + 5; printf("%d", (int)(x & 0xFFFFFFFFLL)); }