GATE | GATE CS 2020 | Question 32

• Difficulty Level : Medium
• Last Updated : 11 Aug, 2021

Consider the following C program.

 #include  int main ()  {     int  a = {{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 _______ .

Note – This question was Numerical Type.
(A) 18
(B) 19
(C) 20
(D) 14

Explanation: Given a is 2D array. Let starting address (or base address) of given array is 1000.

Therefore,

= *(*(a+**a+2)+3))
= *(*(1000+**1000+2)+3))
= *(*(1000+3)+3))   {given element **1002 = 3}
= *(*(1003)+3))
= *((1003)+3)    {4th row selected in given matrix}
= *((1003)+3)     {address of 4th element in 4th row}
= a
= 19            {element selected a = 19}
 #include  int main ()  {     int  a = {{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); }

Option (B) is correct.

My Personal Notes arrow_drop_up