ProgrammingHardTCS NQT · Infosys
int a[] = {4, 9, 16}; int *p = a; What is (p + 2)[-1]?
- A. 9
- B. 16
- C. 4
- D. undefined
Correct answer: A. 9
(p + 2)[-1] is *(p + 1), which is a[1] = 9. Indexing with a negative subscript is valid whenever the resulting address is inside the array.
More C Programming questions
- 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?
- uint32t x = 0xFFFFFFFFu; How many times does while (x > 0) x >>= 1; execute its body, counting from the start?
- int cnt[3] = {0}; int p; for (p = cnt; p < cnt + 3; p++) p = p - cnt; What is the sum of cnt[0] + cnt[1] + cnt[2]?
- A loop while (!(x & 1)) { x >>= 1; c++; } counts the trailing zero bits of a nonzero uint32t x = 0b101000. What is c?