ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {5, 9, 12, 7};
int p[5] = {0};
for (int i = 0; i < 4; i++)
p[i + 1] = p[i] ^ a[i];
printf("%d", p[4] ^ p[1]);
}- A. 7
- B. 2
- C. 5
- D. 12
Correct answer: B. 2
p[4] ^ p[1] equals the XOR of the elements a[1] to a[3], which is 9 ^ 12 ^ 7 = 2. Equal XOR prefixes cancel out, so the range XOR is the answer.
More C Programming questions
- What is printed? c #include <stdio.h> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int a, int…
- What is printed? c #include <stdio.h> int main(void) { signed char c = -1; unsigned char d = c; printf("%d %d", c == d, (int)d); }
- What is printed? c #include <stdio.h> int main(void) { int h = -17; unsigned idx = (unsigned)h % 16u; printf("%u", idx); }
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> struct Person { char name[4]; int age; }; int cmp(const void…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 1, 2, 5, 4}, c = 0; for (int i = 0; i < 5; i++) for (int j = i + 1; j…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t m = 0x0F; for (int i = 0; i < 8; i++) m = (uint8t)((m <<…