I was hoping someone could explain why my professor placed a double pointer in this sample code he gave us. head is declared as Node *head
in main, so why did he pass it in as a double pointer? As far as I can tell it would work the exact same if I dropped the extra star and in the function dropped all the stars on head.
Thanks
void addLast(Node **head, int value)
{
Node *temp;
temp = *head;
Node *var = (Node *)malloc(sizeof (Node));
var->data=value;
if( *head==NULL)
{
*head=var;
(*head)->next=NULL;
}
else
{
while(temp->next!=NULL)
{
temp=temp->next;
}
var->next=NULL;
temp->next=var;
}
}