GATE Computer ScienceHardGATE CSE · TCS
void f(int a[], int n) { a[0] = n; n = a[1]; a = a + 1; a[0] = 99; } int main() { int x[3] = {1, 2, 3}; int m = 5; f(x, m); printf("%d %d %d %d", x[0], x[1], x[2], m); } What is printed?
- A. 5 2 3 2
- B. 5 99 3 2
- C. 5 99 3 5
- D. 1 99 3 5
Correct answer: C. 5 99 3 5
a[0] = n sets x[0] = 5. n = a[1] changes only the local copy, and a = a + 1 moves only the local pointer, so a[0] = 99 writes x[1] = 99. m stays 5.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many structurally distinct binary search trees on 6 keys have height exactly 3, where height is the number of edges on the longest…
- In how many different ways can the keys 1, 2, …, 7 be arranged in the array of a binary max-heap (every parent greater than its children)?
- A binary max-heap is built from 15 elements by Floyd's bottom-up method (sift-down from the last internal node to the root). Each level of…
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } How many times is A…
- Thirteen people numbered 1 to 13 stand in a circle (circular linked list). Starting the count at person 1 (who counts as 1), every 4th…
- A disjoint-set forest over elements 1..8 starts with each element as its own root. It uses union by rank (on equal ranks, the root of the…