When you have a function parameter int& i
, any changes to i inside the function, also change the variable passed to the function. When the parameter is int i
, a copy is made inside the function, and any changes to the parameter do not affect the variable passed to the function.
There's no reason the same logic cannot be applied to pointer parameters. When you have node *n
, a copy of the pointer is made, and if the pointer inside the function is made to point to something else, the pointer that was passed to the function from outside is not changed. When the parameter is node *&n
, if the parameter is made to point to something else inside the function, the pointer variable outside the function which was passed in, is also changed to point to the same thing.
I didn't look too much at the function, but I assume the logic requires this function to update the pointer outside the function call too.