If I pass a pointer P from function f1 to function f2, and modify the contents of P in f2, will these modifications be reflected in f1 automatically?
For example, if I need to delete the first node in a linked list:
void f2( Node *p)
{
Node *tmp = p;
p = p -> next;
delete tmp;
}
Will the changes made to P be reflected in the calling function, or will it now point to a memory space that has been deallocated?
( My intuitive answer here is no, changes are not reflected. However, good sources tell me that the above code will work. Can someone take the time to give the answer and explain the reasoning behind it also please? Also, if the above code is faulty, how can we achieve this without using a return type? )