ProgrammingHardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 0xB5, y = 0x4E, z = x ^ y, c = 0;
while (z) { z &= z - 1; c++; }
printf("%u", c);
}- A. 7
- B. 8
- C. 1
- D. 251
Correct answer: A. 7
x ^ y = 0xB5 ^ 0x4E = 0xFB = 1111 1011, and z &= z - 1 clears one set bit per pass, so c = 7 (the Hamming distance). 8 uses x | y = 0xFF, 1 counts the bits they share (x & y = 0x04), and 251 is the value of x ^ y, not its bit count.
More C Programming questions
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t v = 0; v |= 1u << 3; v |= 1u <<…
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t x = 0x0003, r = 0; for (int…
- 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) {…