1 votes 1 votes closed with the note: Got the solution What is the output of above program? Answer is : 1, 1, 1, 1 2, 2, 2, 2 3, 3, 3, 3 2, 2, 2, 2 3, 3, 3, 3 4, 4, 4, 4 Can anyone explain me those 4 expressions diagrammatically ? Programming in C array-of-pointers + – pranay562 asked Jun 11, 2017 closed Mar 21, 2019 by pranay562 pranay562 479 views comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 0 votes 0 votes i am not sure how the value 4 4 4 4 has come considering the other results we know, (a+2)+3 can be considered as a+5 as well now lets consider the loops i=0 -> j=0 => ultimately i and j is added to p,therefore p[0] which is a[0] and gives 1 i=0->j=1 =>0+1=1: p[1] which gives a[1] and gives 2 i=0 ->j=2=>0+2=2:p[2] which gives a[2] and gives 3 i=1 ->j=0=>1+0=1:p[1] which gives a[1] and gives 2 i=1->j=1=>1+1=2:p[2] which gives a[2] and gives 3 i=1->j=2=>1+2=3: but there is no p[3] so am confused about the last one well,this is my interpretation anybody correct me if i am wrong A_i_$_h answered Jun 17, 2017 selected Nov 4, 2018 by pranay562 A_i_$_h comment Share Follow See 1 comment See all 1 1 comment reply Aashish S commented Jun 17, 2017 reply Follow Share a[0] a[1] a[0][0] a[0][1] a[0][2] a[1][0] a[1][1[] a[1][2] 1 2 3 4 5 6 int *p[]={ (int*)a , (int*)a+1 , (int*)a+2}; means ==> int *p[]={ &a[0][0] , &a[0][1] , &a[0][2]}; for i=0 to 1 & for j=0 to 2 --> *(*(p+i)+j) == *(*(i+p)+j) *(*(p+0)+0) =**p = 1 *(*(p+0)+1) =*(*p + 1) ie *(&a[0][1] ) = 2 *(*(p+0)+2) =*(*p + 2) ie *(&a[0][2] ) = 3 *(*(p+1)+0) =*(*p + 1) ie *(&a[0][1] ) = 2 *(*(p+1)+1) = *(&a[0][1] + 1) ie *(&a[0][2] ) = 3 *(*(p+1)+2) = *(&a[0][1] + 2) ie *(&a[1][0] ) = 4 for i=0 to 1 & for j=0 to 2 --> *(*(p+j)+i) == *(*(j+p)+i) *(*(p+0)+0) =**p = 1 *(*(p+1)+0) =*(*p + 1) ie *(&a[0][1] ) = 2 *(*(p+2)+0) =*(*(p + 2) ie *(&a[0][2] ) = 3 *(*(p+0)+1) =*(*p + 1) ie *(&a[0][1] ) = 2 *(*(p+1)+1) = *(&a[0][1] + 1) ie *(&a[0][2] ) = 3 *(*(p+2)+1) = *(&a[0][2] + 2) ie *(&a[1][0] ) = 4 3 votes 3 votes Please log in or register to add a comment.