There can be following three approaches -
Preference One: Use Double Pointer
void deleteFirst(struct node **head_ref)
{
if(*head_ref != NULL)
{
struct node *temp = *head_ref;
*head_ref = (*head_ref)->next;
free(temp);
}
}
Preference Two: Return head pointer
struct node *deleteFirst(struct node *head)
{
if(head != NULL)
{
struct node *temp = head;
head = head->next;
free(temp);
}
return head;
}
Preference Three: Global Head Pointer (should be avoided)
struct node *head = NULL;
void deleteFirst()
{
if(head != NULL)
{
struct node *temp = head;
head = head->next;
free(temp);
}
}