Look what have i understood from this program .. but the output is different
1 -p1 = address of firstvalue p2= address of second value
2- firstvalue = 10
3- we have put value of 10 in second value
3- we have made address of first and second value same..(not sure)
4-we have changed first value to 20
2nd value is 20 .. i understood but what about 1st value.. why it has been changed? ? ? ?
p1 = &firstvalue; //means you have stored address of firstvalue in pointer p1
p2 = &secondvalue; //means you have stored address of secondvalue in pointer p2
*p1 = 10; /* (*) is derefence operator use to access the contents of address stored in p1.
in this statement you are changing or storing 10(content) at the address stored in p1
i.e of firstvalue */
*p2 = *p1; // assigning the content of p1 i.e 10 to p2(which points to secondvalue)//
p1 = p2; // assigning the address stored in p2(i.e secondvalue) to p1//
*p1 = 20; // same as line 3 ut this time you have assigned address of secondvalue to p1 so it
will assign 20 to secondvalue//