Possible Duplicate:
pass by reference not working
I was going through some of the tutorials linklistproblem of stanford in internet, i got confused the use of “pointer” and “pointer to pointer” in a linklist in page no 5 of the tutorial.
function 1:
changeTonull( &head) //passing by pointer to head pointer of link list
void changeTonull( struct node ** headref) // function defination
{
*headref = NULL;
}
function 2 :
changeTonull(head) // passing head pointer of link list
void changeTonull( struct node * headref) // function defination
{
headref = NULL;
}
in the first function i am passing a pointer to pointer , for changing the value of head pointer of link list to NULL
in the second function i am passing only a pointer , to change the value of head pointer of link list to NULL
So what tutorial says is that it is better to use first function to change the value of head pointer of the link list, why?
you can also check the tutorial linklistproblem page no 5.
The simple answer is that that the tutorial tells you to use the first method because the second one doesn’t work.
The C FAQ’s Question 4.8 is about exactly your problem.