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 4 of 4.
Sunil said:
1 decade ago
Thanks
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
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.
Siba said:
1 decade ago
Its a nice explanation.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers