GATE | GATE CS 2020 | Question 32

Consider the following C program.

filter_none

edit
close

play_arrow

link
brightness_4
code

#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); 
}  

chevron_right


The output of the program is _______ .

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


Answer: (B)

Explanation: Given a[4][5] 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[3][3]
= 19            {element selected a[3][3] = 19} 
filter_none

edit
close

play_arrow

link
brightness_4
code

#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); 
}  

chevron_right


Option (B) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    2


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.