The following is a sample code, not the working one.
I just want to know the difference between *head
and (*head)
in pointers in C.
int insert(struct node **head, int data) {
if(*head == NULL) {
*head = malloc(sizeof(struct node));
// what is the difference between (*head)->next and *head->next ?
(*head)->next = NULL;
(*head)->data = data;
}
*
has lower precedence than ->
so
*head->next
would be equivalent to
*(head->next)
If you want to dereference head
you need to place the dereference operator *
inside brackets
(*head)->next