ProgrammingHardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint16_t x = (uint16_t)~0x00F0u;
int c = 0;
for (; x; x &= x - 1) c++;
printf("%d", c);
}- A. 12
- B. 8
- C. 28
- D. 4
Correct answer: A. 12
Truncating ~0x00F0 to 16 bits gives 0xFF0F, which has 12 set bits. Counting the bits of the original 0x00F0 gives 4, and the 32-bit complement would have 28.
More C Programming questions
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t v = 0x81; v = (uint8t)((v >> 1) | (v << 7))…
- How many times does the loop body run? c #include <stdio.h> int main(void) { unsigned mask = 0x2D, n = 0; for (unsigned s = mask; s; s =…
- Assume unsigned int is 32 bits. What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t a = 70000, b = 70000…
- What is printed? c #include <stddef.h> #include <stdio.h> int main(void) { sizet n = 3; int k = -2; printf("%zu %d", (sizet)(k + n), (n +…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t x = 0x06; uint8t r = 0; for (int i = 0; i < 8; i++) { r…
- What is printed? c #include <stdio.h> unsigned g(unsigned n) { return n ^ (n >> 1); } int main(void) { printf("%u %u", g(10), g(7)); }