ProgrammingHardTCS NQT · Accenture
What is printed? Assume uint16t is 16 bits.
What is printed? Assume uint16_t is 16 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint16_t x = 0x0003, r = 0;
for (int i = 0; i < 16; i++) {
r = (uint16_t)((r << 1) | (x & 1u));
x >>= 1;
}
printf("%d", r);
}- A. 24576
- B. 32768
- C. 49152
- D. 49153
Correct answer: C. 49152
Reading the 16 bits of 0x0003 from the low end and pushing them into r reverses the whole word, giving 0xC000 = 49152. Reversing only the low byte would give 0x00C0.
More C Programming questions
- What is printed? c #include <stdio.h> int t[256]; int main(void) { for (int i = 1; i < 256; i++) t[i] = t[i >> 1] + (i & 1); printf("%d…
- What is printed? Assume uint8t is 8 bits and unsigned int is 32 bits. c #include <stdint.h> #include <stdio.h> uint8t sat(uint8t a, uint8t…
- What is printed? c #include <stddef.h> #include <stdio.h> int main(void) { sizet a = 3, b = 5; printf("%d", (a - b) / 2 > 0); }
- What is printed? c #include <stdio.h> int od(unsigned n); int ev(unsigned n) { return n == 0 ? 1 : od(n - 1); } int od(unsigned n) {…
- A complete binary tree of 7 nodes is stored in an array with children of node i at 2i+1 and 2i+2. The values are v = {5, 3, 8, 1, 4, 9…
- What is printed? c #include <stdio.h> #include <stdlib.h> struct Pair { int a, b; }; int cmp(const void p, const void q) { const struct…