280 views

1 Answer

1 votes
1 votes

When you call fun(p) you are passing the copy of the pointer p and then changing its value. So when the function returns the actual p remains unchanged.

If you wish to make the change persist, then you will have to pass the address of the pointer. This will also mean that you will have to change the signature of the function fun to

 

void fun(int **p){…..*p = &q;}

 

Related questions