title: How to "completely" delete all nodes in a linked list?
body: <p>I got curious about how pointers and deleting pointers worked in C++ so I set up an experiment. I made a very simple singly linked list and the following recursive function that deletes all nodes in a list:</p>
  
  <pre><code>void deleteList(Node *node) {
      if (!node)
          return;
      deleteList(node-&gt;next);
      cout &lt;&lt; "deleting node " &lt;&lt; node-&gt;data &lt;&lt; endl;
      delete node;
      node = nullptr;
  }
  </code></pre>
  
  <p>I suppose that this successfully deletes all nodes in a list. However, after calling this function in main, I check to see if the head node still exists:</p>
  
  <pre><code>List list;
  // appending a bunch of numbers to the list...
  list.deleteList(list.head);
  if (list.head) 
      cout &lt;&lt; true;
  </code></pre>
  
  <p>this will print 1 to the console, meaning that the head does indeed still exist. I would expect the head, and all other nodes after it, to be null and hence that the if condition fails, since setting pointers to null is the last thing I do in the recursive function. So why does the program report that the head still exists?</p>
  
  <p>edit: changed List list(); to List list;</p>