Consider the following C program. #include <stdio.h> int main () { int a[4]…
2020
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 _______.
Attempted by 126 students.
Show answer & explanation
Correct answer: 19
Answer: 19
Explanation:
Find **a: a is a 2D array. *a refers to the first row, and **a is the first element of that row, which is 1.
Compute the pointer expression a + **a + 2: substitute **a = 1 to get a + 1 + 2 = a + 3. This points to the fourth row (index 3).
Dereference and offset: *(a + 3) yields the fourth row (starting at a[3][0]); adding 3 gives the element a[3][3].
Value of a[3][3] is 19, so the expression evaluates to 19 and the program prints 19.
A video solution is available for this question — log in and enroll to watch it.