Problem with getting Pointers

Hi,
I've been trying to figure out the tutorial on pointers on Page 66 of the C++ Language Tutorial(from cplusplus.com) and http://www.cplusplus.com/doc/tutorial/pointers/ (under the subheading "Declaring variables of pointer types",program 2--line 12) where it says
1
2
3
p1=p2    //i get this
/*but here*/
*p1=20     //how does it give p1 the value 20 and again give 10 as output? 


I honestly havent gone beyond that.Please i can catch up with however way you explain
Last edited on
*p1=20 //how does it give p1 the value 20 and again give 10 as output?


It does not give p1 the value 20. It gives the object p1 points at the value 20. What does p1 point to at this part? Same thing as p2 (p1=p2;). OK, so what does p2 point to?

p2 = &secondvalue; // p2 = address of secondvalue
It point to the object secondvalue, so therefore p1 points to the object secondvalue.

What is output as 10? firstvalue. Not secondvalue.

Last edited on
Topic archived. No new replies allowed.