C Programming - Arrays - Discussion

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

int main()
{
    static int arr[] = {0, 1, 2, 3, 4};
    int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
    int **ptr=p;
    ptr++;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    *ptr++;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    *++ptr;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    ++*ptr;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    return 0;
}
0, 0, 0
1, 1, 1
2, 2, 2
3, 3, 3
1, 1, 2
2, 2, 3
3, 3, 4
4, 4, 1
1, 1, 1
2, 2, 2
3, 3, 3
3, 4, 4
0, 1, 2
1, 2, 3
2, 3, 4
3, 4, 5
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
38 comments Page 3 of 4.

Jyoti said:   8 years ago
I don't understand.

Why takes p as 0, and then 0-array as 1?

Abhishek said:   9 years ago
Thank you guys. Got it finally, special thanks to @Leenaja.

Prashant said:   9 years ago
Hi, I am not getting this. Please, anyone explain me.

Saurabh tiwari said:   1 decade ago
Please give me solid answer with fully explanation.

Neeraj said:   8 years ago
What if the array arr is not declared as static?

Kushal said:   1 decade ago
I can't understand the last row. Why's it 3 4 4?

Dileep said:   9 years ago
Can't understand this? Please help me to get it.

Jitendra said:   1 decade ago
Where give ptr is point to a pointer ?

Rahul said:   1 decade ago
Please anyone explain this in detail.

Anand shiva said:   2 decades ago
Please give me a brief description.


Post your comments here:

Your comments will be displayed after verification.