C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 5)
5.
What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>

int main()
{
    int ***r, **q, *p, i=8;
    p = &i;
    q = &p;
    r = &q;
    printf("%d, %d, %d\n", *p, **q, ***r);
    return 0;
}
8, 8, 8
4000, 4002, 4004
4000, 4004, 4008
4000, 4008, 4016
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
35 comments Page 3 of 4.

Sujan said:   9 years ago
p=&i;
therefore, *p=i; -> *p=8;

q=&p;
therefor, *q=p; **q=*p; -> **q=8;

r=&q;
therefor *r=q; **r=*q; ***r=**q=8!

Abi said:   9 years ago
@All. Thank you for the explanation.

Shefali said:   9 years ago
@Jyothi is explained well.

Keerthana said:   9 years ago
Thanks for your answers.

Akshansh Yadav said:   9 years ago
Great explanations. Thank you all.

SONY said:   9 years ago
Thank you all for providing very good explanations.
(2)

Sujit said:   8 years ago
@Jyothi.

The Explanation is perfect. Thanks.

Shivani agrawal said:   8 years ago
i=8;
p=&i implies *p=8;
q=&p implies *q=p means **q=8;
r=&q implies *r=q means ***r=8;
So, *p=**q=***r=i=8;.
(1)

Sujata said:   8 years ago
@Sunil Pradhan.

Well explained, thanks!
(1)

Preethi said:   8 years ago
Thank you @Keerthi. Nice explanation.


Post your comments here:

Your comments will be displayed after verification.