title: access violation writing location c++ linked list
body: <p>I'm trying to write a function that takes a pointer to the head node, and then reverse the way the node links to each other using a recursion.</p>
  
  <p>below is my function.</p>
  
  <pre><code>void reverseRec(digits *&amp;head){
  digits *temp = head;
  if(temp-&gt;next = NULL){
      head = temp;
      return;
    }
  reverseRec(head-&gt;next);
  digits * a = temp-&gt;next;
  a-&gt;next = temp;
  temp-&gt;next = NULL;
  }
  </code></pre>
  
  <p>and the function is called as follow: </p>
  
  <pre><code>int main(){
      digits * head = new digits(); // pointer that points to head of the node
      head = NULL;
      insert(head, 5, 1); 
      insert(head, 6, 2);
      insert(head, 1, 3);
      insert(head, 7, 1);
      delList(head, 1);
      reverseRec(head);
  }
  </code></pre>
  
  <p>if it helps, I tried using a normal reverse function using a while loop, and it turned just fine, my code is like this:</p>
  
  <pre><code>void reverse(digits *&amp;head){
      digits * prev, * current, * next;
      current = head;
      prev = NULL;
      while(current!= NULL){
          next = current-&gt;next;
          current-&gt;next = prev;
          prev = current;
          current = next;
      }
      head = prev;
  }
  </code></pre>
  
  <p>I'm new to C++, I get A LOT of those 'access violation writing location' errors, and until now I don't know what it is (I usually tinker with the code until it get fixed, but I never really understand what causes this). </p>
  
  <p>sorry it's really a newbie question, what are these access violation writing location error? what is wrong with my code? </p>