ProgrammingHardTCS NQT · Infosys
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?
- A. 2
- B. 5
- C. 4
- D. 6
Correct answer: B. 5
The loop reverses the array, giving {6, 5, 4, 3, 2, 1}. The element at index 1 becomes 5.
More C Programming questions
- 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…
- int a[] = {4, 9, 16}; int p = a; What is (p + 2)[-1]?
- To compute a b mod m with 0 <= a, b < m <= 1000000007 in a competitive program, which expression is correct?
- Which expression tests whether bit k of an unsigned x is set?
- int x = 0x1F; What does printf("%d", 07 + 0x1F) print?