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;
}
Discussion:
35 comments Page 2 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!
therefore, *p=i; -> *p=8;
q=&p;
therefor, *q=p; **q=*p; -> **q=8;
r=&q;
therefor *r=q; **r=*q; ***r=**q=8!
Arnab Bhattacharya said:
1 decade ago
Thank you Sunil Pradhan!
The way you have explained is very easy to understand the concept clearly. Hope more posts from you.
The way you have explained is very easy to understand the concept clearly. Hope more posts from you.
Sumallika said:
1 decade ago
p=&i
*p=*(&i)=i
so *p=8;
q=&p,
*q=*(&p)=p,
**q=*p,
**q=8;
r=&q,
*r=*(&q)=q
**r=*q,
***r=**q,
***r=8
*p=*(&i)=i
so *p=8;
q=&p,
*q=*(&p)=p,
**q=*p,
**q=8;
r=&q,
*r=*(&q)=q
**r=*q,
***r=**q,
***r=8
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;.
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)
Harendra gotla said:
9 years ago
Thank you @Sumallika, the way you solve the problem is clever and easy to understand.
Manjiri shastri said:
10 years ago
Can you please tell me how it work? I mean how pointer storing the address?
Swadhinur said:
1 decade ago
Keerthi the way you describe is the right concept of this problem.
SONY said:
9 years ago
Thank you all for providing very good explanations.
(2)
Tarun said:
1 decade ago
@Jyothi. Explain nicely thanks for understand me.
Sujit said:
8 years ago
@Jyothi.
The Explanation is perfect. Thanks.
The Explanation is perfect. Thanks.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers