ProgrammingHardTCS NQT · Infosys
int a[] = {5, 1, 4}; int *p = a; *p++ += 10; printf("%d %d", a[0], *p); prints what?
- A. 5 11
- B. 15 4
- C. 15 1
- D. 5 1
Correct answer: C. 15 1
*p++ applies to the old pointer value: the element a[0] gains 10 and becomes 15, then p advances to a[1], which holds 1.
More C Programming questions
- struct P { int id; int score; }; An array must be sorted by score descending, with ties broken by id ascending, using qsort. Which…
- For a = {2, 4, 2, 2, 6, 4}, how many index pairs i < j satisfy a[i] == a[j]?
- uint32t fact(uint32t n) { return n <= 1 ? 1 : n fact(n - 1); } What does fact(13) return?
- uint8t acc = 0; uint8t a[3] = {250, 3, 7}; for each element, acc += a[i]; What is acc after all three additions?
- 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]?
- 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?