title: Using pointers to remove item from singly-linked list
body: <p>In a recent <a href="http://meta.slashdot.org/story/12/10/11/0030249/linus-torvalds-answers-your-questions" rel="noreferrer">Slashdot Interview</a> Linus Torvalds gave an example of how some people use pointers in a way that indicates they don't really understand how to use them correctly. </p>
  
  <p>Unfortunately, since I'm one of the people he's talking about, I also failed to understand his example:</p>
  
  <blockquote>
    <p><em>I've seen too many people who delete a singly-linked list entry by keeping track of the "prev" entry, and then to delete the entry, doing
    something like</em></p>
  
  <pre><code>if (prev)
      prev-&gt;next = entry-&gt;next;
  else
      list_head = entry-&gt;next;
  </code></pre>
    
    <p><em>and whenever I see code like that, I just go "This person doesn't
    understand pointers". And it's sadly quite common. People who
    understand pointers just use a "pointer to the entry pointer", and
    initialize that with the address of the list_head. And then as they
    traverse the list, they can remove the entry without using any
    conditionals, by just doing</em></p>
  
  <pre><code>*pp = entry-&gt;next
  </code></pre>
  </blockquote>
  
  <p>Can someone provide a bit more explanation about why this approach is better, and how it can work without a conditional statement?</p>