ProgrammingVery hardProduct company OA
What is printed?
What is printed?
unsigned char rotl(unsigned char v, int k) {
return (unsigned char)(v << k | v >> (8 - k));
}
int main(void) {
printf("%02X %02X", rotl(0x96, 3), rotl(rotl(0x96, 3), 5));
}- A. 4B 96
- B. B4 69
- C. B4 96
- D. B0 96
Correct answer: C. B4 96
0x96 = 1001 0110. Rotating left by 3 moves the top three bits (100) to the bottom: 1011 0100 = 0xB4. Rotating by 5 more completes 8, a full circle, giving 0x96 back. 'B0' is a plain shift that loses the wrapped bits.
More C Programming questions
- With int a[3], p = a; which statement fails to compile?
- Assume 4-byte int. What is printed? c struct Msg { int len; char data[]; }; struct Msg m = malloc(sizeof m + 10); printf("%zu", sizeof m);
- What is printed? c printf("%zu %zu", sizeof("ab" "cd"), strlen("ab0cd"));
- What is printed? c int n = printf("%d", printf("%s", "abc")); printf(" %d", n);
- What is printed? c int f(int n, int b) { return n < b ? 1 : 1 + f(n / b, b); } int main(void) { printf("%d %d %d", f(1000, 2), f(1000…
- What is printed? c const char s = "education"; int v = 0, o = 0; for (; s; s++) switch (s) { case 'a': case 'e': case 'i': case 'o': case…