closed by
478 views
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​ ?

closed by

1 Answer

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
selected by

Related questions

4 votes
4 votes
2 answers
1
sh!va asked Jul 16, 2016
1,225 views
In C/C++ an array of pointers is same as(A) Pointer to array(B) Pointer to pointer(C) Pointer to function (D) Pointer to structure
0 votes
0 votes
1 answer
2
mohit chawla asked Sep 18, 2016
539 views
Please help me out guys