title: Nullifying a value from a pointer
body: <p>I haven't done pointer arithmetic in a long time, so I figured I'd try my hand at C and do a simple Binary Search Tree. I can't get the hang of deletion, however. Something along these lines works as I expect:</p>
  
  <pre><code>typedef struct Node{
      int value;
      struct Node *left;
      struct Node *right;
  }Node;
  
  typedef struct Tree{
      struct Node* root;
  }Tree;
  
  int main(){
      Tree *tree = createTree(); 
  
      treeInsert(10, tree);    // Inserts 10 at root
      treeInsert(30, tree);    // Inserts 30 to root-&gt;right
      treeInsert(5, tree);     // Inserts 5 to root-&gt;left
      treeInsert(7, tree);     // Inserts 7 to root-&gt;left-&gt;right
      treeInsert(12, tree);    // Inserts 12 to root-&gt;right-&gt;left
  
      // Removes Node "7" from the tree successfully
      free(tree-&gt;root-&gt;left-&gt;right);   // Free memory for this node in the tree
      tree-&gt;root-&gt;left-&gt;right = NULL;  // Set the pointer to NULL
  
      return 0;
  }
  </code></pre>
  
  <p>I'd like to write a <code>nodeDelete(Node *killNode)</code> function to free the memory associated with a node, then point it to NULL, but I find it doesn't work like I expect it to.</p>
  
  <pre><code>int main(){
     // ... snip ...
  
     Node *kill = tree-&gt;root-&gt;left-&gt;right  // Points kill node to Node "7"
     free(kill);                           // Deallocates memory
     kill = NULL;                          // Points kill to NULL, but keeps 
                                           //   tree-&gt;root-&gt;left-&gt;right **undefined** 
     // ... snip ...
  }
  </code></pre>
  
  <p>I think my problem is that I'm telling it that <code>kill</code> now points to NULL, which disconnects it from the node in the tree and doesn't effect the original node pointer. How can I tell it that I want to point <code>tree-&gt;root-&gt;left-&gt;right</code> to NULL instead of <code>kill</code>? Do I need a pointer-to-a-pointer in this case?</p>