ProgrammingVery hardGATE CS · Campus placements
int a[] = {3, 5, 6, 9}; int pre[5]; pre[0] = 0, and pre[i] = pre[i-1] ^ a[i-1] for i = 1..4. What is pre[4] ^ pre[1]?
- A. 10
- B. 3
- C. 12
- D. 14
Correct answer: A. 10
pre[4] ^ pre[1] equals a[1] ^ a[2] ^ a[3] = 5 ^ 6 ^ 9 = 10. Prefix XOR arrays answer any range XOR this way in O(1) per query.
More C Programming questions
- void f(int a) { sizet n = sizeof a / sizeof a[0]; ... } is called as f(arr) where int arr[4]. What is true about n?
- unsigned int n = 0u; int i = 0; if (i < n - 1) printf("loop"); What is printed?
- Is the C standard guaranteed to remove stack frames of tail-recursive calls, so that deep tail recursion cannot overflow the stack?
- int a[6] = {1, 2, 3, 4, 5, 6}; int p = a, q = a + 5; while (p < q) { int t = p; p++ = q; q-- = t; } What is a[1] afterwards?
- uint8t x = 0xB4; What is the lowest set bit of x, computed as x & (uint8t)-x?
- uint8t rev(uint8t x) { uint8t r = 0; for (int i = 0; i < 8; i++) { r = (uint8t)((r << 1) | (x & 1)); x >>= 1; } return r; } What is…