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 1 of 4.
Kiran Kumar said:
1 decade ago
i = 8
(Assume)address = 100
p = 100 (*p is 8)
address = 200
q = 200 (**q is 8 ) and (*q is 100)
address is 300
r = 300 (***r is 8)&(**r is 100)&(*r is 200)
address = 400
therefore, i = *p = **q = ***r = 8.
(Assume)address = 100
p = 100 (*p is 8)
address = 200
q = 200 (**q is 8 ) and (*q is 100)
address is 300
r = 300 (***r is 8)&(**r is 100)&(*r is 200)
address = 400
therefore, i = *p = **q = ***r = 8.
Shubham Patil said:
6 years ago
Here i = 8.
1) As p=&i is representing the value of i is 8.
2) q=&p => stores the address of p.
*q is the address stored in q ie address of p.
**q = value at address at p i.e. 8.
3) r=&q
Therefore *r= address of q.
**r= *(*q).
***r= *(*(*q)).
That i the value stored in p = 8.
Hence the answer is 8 8 8.
1) As p=&i is representing the value of i is 8.
2) q=&p => stores the address of p.
*q is the address stored in q ie address of p.
**q = value at address at p i.e. 8.
3) r=&q
Therefore *r= address of q.
**r= *(*q).
***r= *(*(*q)).
That i the value stored in p = 8.
Hence the answer is 8 8 8.
(5)
Madhu said:
1 decade ago
If it declaired that int i,*p then
p= &i (it means p stores the address of i)
*p=value at i
same way
q= &p
**q=value at &i(it means pointer to a integer pointer)
***r= value at &i(it means pointer to a pointer to a poiter )
and it has no limit to extend this pointer to pointer so we can use number of' *'.but all are print only the value so it prints 8,8,8.
p= &i (it means p stores the address of i)
*p=value at i
same way
q= &p
**q=value at &i(it means pointer to a integer pointer)
***r= value at &i(it means pointer to a pointer to a poiter )
and it has no limit to extend this pointer to pointer so we can use number of' *'.but all are print only the value so it prints 8,8,8.
Uttam said:
1 decade ago
Let the addresses of variables i,p,q,r are 0x100,0x200,0x300,0x400 respectively.
Here p,q,r are pointers.
p holds address of i.ie 0x100.
q holds address of p.ie 0x200.
r holds address of q.ie 0x300.
so we can say r is the pointer which indirectly refers to the address of variable i.
so value that pointer r holds is indirectly equal to the value of i.
Here p,q,r are pointers.
p holds address of i.ie 0x100.
q holds address of p.ie 0x200.
r holds address of q.ie 0x300.
so we can say r is the pointer which indirectly refers to the address of variable i.
so value that pointer r holds is indirectly equal to the value of i.
Keerthi kumar said:
1 decade ago
Initially i=8 (given integer is 4 bytes long)
p=&i implies address of i (4000)
q=&p implies address of p (4004)
r=&q implies address of q (4008)
output
*p=8,
**q since q=4004
*q=4000
**q=8
***r since r=4008
*r=4004
**r=4000
***r=8 hence output is 8,8,8
p=&i implies address of i (4000)
q=&p implies address of p (4004)
r=&q implies address of q (4008)
output
*p=8,
**q since q=4004
*q=4000
**q=8
***r since r=4008
*r=4004
**r=4000
***r=8 hence output is 8,8,8
Sunil pradhan said:
1 decade ago
Here each * means address holding it i.e. 'p' holds address of 'i', *p value at i = 8.
'q' holds address of p, p holds address of 'i'. So with two ** we are back to value at i = 8.
Similarly, three times *** means jump from r to q to p that holds i = 8.
'q' holds address of p, p holds address of 'i'. So with two ** we are back to value at i = 8.
Similarly, three times *** means jump from r to q to p that holds i = 8.
Perumalsamy said:
1 decade ago
First assume i=8
and then
p =&i; // p holds address of i
q=&p; // q holds address of p
r=&q; // and r holds address of q
*p means value of i;
**q and ***r and is called chain pointer that means
p<-q<-r
So all value is 8.
and then
p =&i; // p holds address of i
q=&p; // q holds address of p
r=&q; // and r holds address of q
*p means value of i;
**q and ***r and is called chain pointer that means
p<-q<-r
So all value is 8.
Ramya said:
1 decade ago
Here r contains ***r so it point the i pointer variable.
And q contain the ** pointer variable. And p contain the * pointer variable so it point the i pointer address value.
And q contain the ** pointer variable. And p contain the * pointer variable so it point the i pointer address value.
Vivek said:
1 decade ago
*p=value in (&i)=8
q=&p
then **q=value in (p=(value in(&i))=8
r=&q
then ***r=value in (q=(value in(p=(value in &i)))=8
q=&p
then **q=value in (p=(value in(&i))=8
r=&q
then ***r=value in (q=(value in(p=(value in &i)))=8
Jyothi said:
1 decade ago
p=&i;
means: *p=i; [*p=8]
q=&p;
means : *q=p => **q=*p => **q=8
r=&q => *r=q =>***r=**q =>***r=8;
so, 8,8,8
means: *p=i; [*p=8]
q=&p;
means : *q=p => **q=*p => **q=8
r=&q => *r=q =>***r=**q =>***r=8;
so, 8,8,8
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers