I have a pointer to a struct object in C++.
node *d=head;
I want to pass that pointer into a function by reference and edit where it points. I can pass it but it doesn’t change where the initial pointer points but only the local pointer in the function. The arguments of the function must be a pointer right? And after how do I change it to show to a different object of the same struct?
You have two basic choices: Pass by pointer or pass by reference. Passing by pointer requires using a pointer to a pointer:
Passing by reference uses
&:If you pass the pointer as just
node *d, then modifyingdwithin the function will only modify the local copy, as you observed.