C++ pointer confusion (Binary Search Tree)
<pre><code>struct node{
  int element;
  node* left;
  node* right;
};

typedef node* SET;

void INSERT(int x, SET* A){
  node* pA = *A;
  if (pA == NULL){
    pA = new node;
    pA-&gt;element = x;
    pA-&gt;left = NULL;
    pA-&gt;right = NULL;
  }
  else{
    if (x &lt; pA-&gt;element){
      INSERT(x,&amp;(pA-&gt;left));
    }
    else if (x&gt;pA-&gt;element){
      INSERT(x, &amp;(pA-&gt;right));
    }
  }
}

int main(){
  node* A = NULL;
  INSERT(1,&amp;A);
  cout &lt;&lt;A-&gt;element&lt;&lt;endl;
  return 0;
}
</code></pre>

<p>The Code above is a simple insertion method that will insert an element into the BST. I just keep getting segment default when I access A->element. Many Thanks from your answer.</p>

<p><strong>Edit:</strong></p>

<p>wow, this pointer stuff is really confusing. So when I do node* pA = *A, I thought I would create a pointer pointing to the location of A. Then when I do pA = new node, it would create a node object in the heap pointing by pA which is the same as A. Am I saying anything wrong?</p>
