title: why using a local pointer wouldn't work
body: <pre><code>inline void insert(node *root, int value)
  {
      if(!root)
      {
          root = new node();
          root-&gt;value = value;
      }
      else
      {
          node *itr = root;
          while(1)
          {
              if(itr-&gt;value &gt; value)
                  itr = itr-&gt;left;
              else
                  itr = itr-&gt;right;
              if(!itr)
              {
                  itr = new node();
                  itr-&gt;value = value; 
  
                  break;
              }
  
          }
      }
  }
  </code></pre>
  
  <p>//call insert function like this</p>
  
  <pre><code>node *head = 0;
  insert(head, 5);
  insert(head, 10);
  insert(head, 3);
  insert(head, 1);
  insert(head, 4);
  </code></pre>
  
  <p>I know this code wouldn't work because 'itr' in <em>insert</em> function is a local variable, thus, it wouldn't reflect the tree outside of the method. 
  However, I don't clearly understand why it wouldn't work. 
  Although 'itr' is a local variable, 'itr' points to the same location where 'root' points to. Also, I am dereferencing it to move 'left' or 'right' so I think it should work. </p>
  
  <p>I think this is a basic problem of passing a pointer by value vs pointer but I couldn't find a clear explanation of why I can't change the tree using a local variable of a pointer.</p>