title: About reference to pointers
body: <p>I've been making a tree, because planting a trees will save the planet (or just the program).</p>
  
  <pre><code>class Tree {
    Node* root;
    // ...
    void insert(int value){
      private_insert(value, root);
    }
    void insert_private(int value, node* n){
      if(n == nullptr){
        n = new node(value);
      } else {
        your standard recursive insertion function here
      }
    }
    // ...
  };
  </code></pre>
  
  <p>Long story short i've tried using shared_ptrs first, but the the insert() function will never add any element into my tree. I thought i might be doing something wrong with shareds so i tried raw pointers and i got the same non-inserty resoults. </p>
  
  <p>Turns out i need to pass a reference my root/nodes.</p>
  
  <pre><code>void insert_private(int value, node*&amp; n) {...};
  </code></pre>
  
  <p>I understand that if i dont pass something as reference then a copy is made. But if a pointer holds an address, doesnt it's copy hold the same address? if i make a new() to a non-referenced pointer why doesnt it stick to my root/nodes?</p>
  
  <p>The why is my question here, i can accept it that it works like this, my tree works, but i dont know why its like this.</p>
  
  <p>edit: After reading the comments i created this small expert level program:</p>
  
  <pre><code>void fn(int* i){
    cout &lt;&lt; "Address of local in fn before change: " &lt;&lt; i &lt;&lt; endl;
    i = new int(2);
  // so basically here we made a new int, and i will get the address of 
  // this integer and will point to there, what we passed on before 
  // becomes irrelevant
    cout &lt;&lt; "Address of local in fn after change: " &lt;&lt; i &lt;&lt; endl;
  }
  void fn2(int **i){
    cout &lt;&lt; "Address of local in fn2 before change: " &lt;&lt; i &lt;&lt; endl;
    *i = new int(2);
    cout &lt;&lt; "Address of local in fn2 after change: " &lt;&lt; i &lt;&lt; endl;
  }
  int main(){
    int* p = nullptr;
    cout &lt;&lt; "Address of p: " &lt;&lt; p &lt;&lt; endl;
    fn(p);
    cout &lt;&lt; "p&amp; is: " &lt;&lt; &amp;p &lt;&lt; endl;
    fn2(&amp;p);
  
    cin.get();
    return 0;
  };
  </code></pre>
  
  <p>Thank you, everyone, for the answers, it helped a lot. random.org will determine who's the one who will get the approved answer thing. </p>