ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned a = 0x12345678u, b = 0x12345600u, x = a ^ b;
int c = 0;
while (x) { c += x & 1u; x >>= 1; }
printf("%d", c);
}- A. 4
- B. 3
- C. 5
- D. 8
Correct answer: A. 4
a ^ b is 0x78, which has four set bits, so these two values differ in exactly four bit positions.
More C Programming questions
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t acc = 0; uint8t v[] = {200…
- What is printed? Assume uint32t is 32 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint32t a = 70000, b = 70000…
- What is printed? c #include <stdio.h> int main(void) { long long a = 1LL << 40; int b = (int)(a >> 20); printf("%d", b); }
- What is printed? c #include <stdio.h> int main(void) { int a[] = {4, 2, 5, 1}; for (int i = 0; i < 3; i++) printf("%d ", a[i] > a[i + 1] ?…
- How many pairs (i, j) with i < j have a[i] XOR a[j] equal to 5 for a = {1, 2, 3, 4}? Compute with this program. c #include <stdio.h> int…
- What is printed? c #include <stdio.h> struct N { int v; struct N nx; }; struct N rev(struct N h, struct N prev) { if (!h) return prev…