GATE 2020 CS – Question 32
Consider the following C program.
#include <stdio.h>
int main() {
int a[4][5]={{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20}};
printf("%d\n", *(*(a+**a+2)+3));
return(0);
}The output of the program is ______.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 19 to 19
Explanation
`a` is a $4\times5$ array. Evaluate `*(*(a+**a+2)+3)`:
- `**a` is `*(*a)=*(a[0])=a[0][0]=1`.
- `a + **a + 2` is `a + 1 + 2 = a + 3`, which points to **row 3**.
- `*(a+3)` is row 3 (as a pointer to its first element, `a[3][0]`).
- `*(a+3) + 3` points to `a[3][3]`.
- The outer `*` reads `a[3][3]`.
Row 3 is `{16, 17, 18, 19, 20}`, so `a[3][3] = 19`. Output: **19**.