title: binary tree recursive insertion with pointer to pointer
body: <pre><code>void insert(node ** tree, int val)
  {
      node *temp = NULL;
      if(!(*tree))
      {
          temp = (node *)malloc(sizeof(node));
          temp-&gt;left = temp-&gt;right = NULL;
          temp-&gt;data = val;
          *tree = temp;
          return;
      }
  
      if(val &lt; (*tree)-&gt;data)
      {
          insert(&amp;(*tree)-&gt;left, val);
      }
      else if(val &gt; (*tree)-&gt;data)
      {
          insert(&amp;(*tree)-&gt;right, val);
      }
  }
  </code></pre>
  
  <p>This function uses a pointer to pointer <code>node ** tree</code> to represent the head of the binary tree. I came across the same method on many tutorials and websites. I wanted to know why everyone insists on using pointer to pointer and why not just 'node * tree'. I presume even pointer to head of tree would do the job just fine, and using just pointer to head of the tree the recursive calls would be as follows (please correct me if i am wrong):</p>
  
  <pre><code>insert(tree-&gt;left, val); // assuming definisiton as void insert(node *tree, int val);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>insert(tree-&gt;right, val); // assuming definisiton as void insert(node *tree, int val);
  </code></pre>
  
  <p>Please correct me if my understanding is wrong. I am a newbie. Thanks.</p>