What will be the output of the following C program?
int a[2][3] = {{1,2,3},{4,5,6}};
printf("%d", *(*(a+1)+2));
Options
-
A.
3
-
B.
5
-
C.
6
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
C.
6
Detailed Explanation
Correct Answer: 6
The two-dimensional array is:
{1, 2, 3}
{4, 5, 6}
a + 1 points to the second row. Dereferencing it using *(a+1) gives access to the second row.
Then +2 moves to the third element of that row, and the final * obtains its value.
Therefore, *(*(a+1)+2) refers to a[1][2], whose value is 6.