ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 0xABCD, p = 0;
while (x) { p ^= x & 1u; x >>= 1; }
/* p is the parity of the set bits of 0xABCD */
printf("%u", p);
}- A. 1
- B. 0
- C. 10
- D. 2
Correct answer: B. 0
0xABCD has 2 + 3 + 2 + 3 = 10 set bits, and XORing each bit into p leaves the parity of that count, which is 0.
More C Programming questions
- 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…
- How many pairs (i, j) with i < j satisfy a[i] < a[j] for a = {3, 1, 4, 2}? Compute with this program. c #include <stdio.h> int main(void)…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}, cnt[3], total = 0; for (int i = 0; i < 3; i++) { cnt[i] = 1…