C Programming - Arrays - Discussion

Discussion Forum : Arrays - Find Output of Program (Q.No. 2)
2.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    static int a[2][2] = {1, 2, 3, 4};
    int i, j;
    static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++)
        {
            printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), 
                                    *(*(i+p)+j), *(*(p+j)+i));
        }
    }
    return 0;
}
1, 1, 1, 1
2, 3, 2, 3
3, 2, 3, 2
4, 4, 4, 4
1, 2, 1, 2
2, 3, 2, 3
3, 4, 3, 4
4, 2, 4, 2
1, 1, 1, 1
2, 2, 2, 2
2, 2, 2, 2
3, 3, 3, 3
1, 2, 3, 4
2, 3, 4, 1
3, 4, 1, 2
4, 1, 2, 3
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
78 comments Page 6 of 8.

Riya said:   8 years ago
Not understanding. Please explain it for me.

Gopi said:   9 years ago
Thank you for you answer @Sindhu and @Chand.

Vivek gupta said:   1 decade ago
I can not understand it please explain more.

Anonymous said:   8 years ago
Can you explain how p=0 in the first step?

Amit said:   4 years ago
@Manju.

You explained it clearly. Thanks.
(1)

Subham said:   1 decade ago
Please explain how *(*(p+1) +0) =a[1].

Sri said:   1 decade ago
Hi. Please explain why we assign p=0?

Sitakanta Mishra said:   1 decade ago
Anyone please explain this question.

Rahul aarthi said:   1 decade ago
i did't get u pls explain clearly

Priyal said:   8 years ago
Thank you for you answer @Dilip.


Post your comments here:

Your comments will be displayed after verification.