ProgrammingHardGATE CS · TCS NQT
What is printed? Assume uint8t is 8 bits.
What is printed? Assume uint8_t is 8 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint8_t x = 0x1C;
int c = 0;
for (int i = 7; i >= 0 && !((x >> i) & 1u); i--)
c++;
printf("%d", c);
}- A. 2
- B. 4
- C. 5
- D. 3
Correct answer: D. 3
0x1C is 00011100, so the three top bits are zero before the first set bit. The loop counts those leading zeros.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 3, r = 0; for (int i = 0; i < 4; i++) { r = (r << 1) | (x & 1u); x >>=…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xABCD, p = 0; while (x) { p ^= x & 1u; x >>= 1; } / p is the parity…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t a = 0xFFFFFFF0u, b = 0x20u; uint32t s = a + b; int…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { int16t a = 200, b = 200; int p = a b; printf("%d %d", p, p >…
- What is printed? c #include <stdint.h> #include <stdio.h> uint16t sat(uint16t a, uint16t b) { uint32t p = (uint32t)a b; return p > 65535u…
- What is printed? c #include <stdio.h> int main(void) { int m[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = i 4…