retagged by
23,223 views
36 votes
36 votes

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 _______.

retagged by

2 Answers

Best answer
50 votes
50 votes

'$a$' is a two dimensional array.

  • $a =$ address of $0^{th}$ index of 2-D array which means address of 1-D array
  • $^*a =$  address of $0^{th}$ index element of $0^{th}$ index 1-D array
  • $^{**}a =$ value at $0^{th}$ index element of $0^{th}$ index 1-D array
    • $\implies ^{**}a = 1$
    • $\implies ^{**}a+2 = 1+2 = 3$
  • $a+3 =$ address of $3^{rd}$ index 1-D array
  • $^*(a+3) = $ address of $0^{th}$ index element of $3^{rd}$ index 1-D array
  • $^*(a+3)+3 =$ address of $3^{rd}$ index element of $3^{rd}$ index 1-D array
  • $^*(^*(a+3)+3) =$ value at $3^{rd}$ index element of $3^{rd}$ index 1-D array $= 19$

Correct Answer: $19.$

selected by
7 votes
7 votes

Answer : 19

a[4] [5] = {{1, 2, 3, 4, 5},

                   {6, 7,8, 9, 10},

                 {11, 12, 13, 14, 15},

                 {16, 17,18, 19, 20}};

Lets solve step-by step :   

step1-   * ( * ( a + ( * ( * a ) ) + 2 ) + 3 )           // note :     ( *(* a)) = 1

step2-    * ( * ( ( (a + 1 )+ 2) ) + 3 )                 

step3-    * ( * ( a + 3) +3)                                // note :    *(a+3)   is address of the memory location where                                                                                                                                           16 is stored or address of 4th row

step4-    * ( * ( a + 3) +3)                                // note. :    *(a+3)+3 now its the address of 4th row and 4th column index.                                                                                                                (a+0) is 1st row so a+3 is 4th row or address of 19

step5-    * ( * ( a + 3) +3)  means value stored at 4th row and 4th column .

so , 19

Answer:

Related questions

38 votes
38 votes
3 answers
1
15 votes
15 votes
5 answers
2
Arjun asked Feb 12, 2020
9,051 views
Let $\mathcal{R}$ be the set of all binary relations on the set $\{1,2,3\}$. Suppose a relation is chosen from $\mathcal{R}$ at random. The probability that the chosen re...
15 votes
15 votes
4 answers
3
Arjun asked Feb 12, 2020
9,066 views
Let $G$ be a group of $35$ elements. Then the largest possible size of a subgroup of $G$ other than $G$ itself is _______.
12 votes
12 votes
2 answers
4