title: What is the reason for using a double pointer when adding a node in a linked list?
body: <p>The two code examples below both add a node at the top of a linked list.
  But whereas the first code example uses a double pointer the second code example uses a single pointer</p>
  
  <p><strong>code example 1:</strong></p>
  
  <pre><code>struct node* push(struct node **head, int data)
  {
          struct node* newnode = malloc(sizeof(struct node));
          newnode-&gt;data = data;
          newnode-&gt;next = *head;
          return newnode;
  }
  
  push(&amp;head,1);
  </code></pre>
  
  <p><strong>code example 2:</strong></p>
  
  <pre><code>struct node* push(struct node *head, int data)
  {
          struct node* newnode = malloc(sizeof(struct node));
          newnode-&gt;data = data;
          newnode-&gt;next = head;
          return newnode;
  }
  
  push(head,1)
  </code></pre>
  
  <p>Both strategies work. However, a lot of programs that use a linked list use a double pointer to add a new node. I know what a double pointer is. But if a single pointer would be sufficient to add a new node why do a lot of implementations rely on double pointers?</p>
  
  <p>Is there any case in which a single pointer does not work so we need to go for a double pointer?</p>