I am still trying to understand pointer to a pointer better. I understand that when you want to change the value of a pointer when passing to a function, you must pass a pointer to that pointer, hence something like :
the value of the array gets updated to 20? I thought it only gets a copy of arr and should not update its value?
Any explanations to clarify my understand would be appreciated.
Thanks a bunch!
when calling ptop(&i), you pass the address of the variable i (it does not matter that i is a pointer, too). Within ptop, the assignment (*i) = 10 dereferences this pointer, so you are setting the variable i (from main!) to 10, not the value i points to. If you now output i, the result will of course be 10.
In a nutshell, you are manipulating manipulating the variable i (from main) the whole time, and not the value i points to. If you try to dereference i, you should get a segfault.