Assume address of r = 1000
So, in the main function is p is holding the value = 1000
Now you called fun(p);
What, happens here ?
New stack frame is allocated for funciton fun().
Argument of fun() is int *p so a new pointer variable named p is also created in this stack frame and p is initialized to 1000 because of parameter passing. So far so good ! :)
Now, again another local varibale is q is allocated and initialized to 10. Assume its adress is 2000.
Then, inside fun() value of local pointer varibale p is changed to 2000.
Keep in mind that p in the stack frame of fun() is different from p in the main function. In the main funciton p is pointing to 1000.
after that you have done some printing stuff inside the fun().
Did you change pointer p in the main function ? NO
Did you change the value contained in the address 1000 ? NO.
So, why should the *p or r value change in the main function ? No change.