Ignoring the mysterious "z" in body of fun,
when we call fun from main, the address of r(say 1000) which is stored in p is copied to "p" in fun,
In fun, we are not changing the value at this address 1000, what we're doing in line p=&q is changing the address itself, i.e now p of fun holds another address(say 2000). so back in main, there are no changes, the p of main still holds the address 1000, which has value 20
Now to be more clear about when value changes and when it doesn't, try this: copy-paste this code and add line *p=30(or any random int value you can think of) in fun before p=&q line once, then move it below p=&q, observe the changes in output.