title: Recursive linked list reversal
body: <p>This code is from <a href="https://www.geeksforgeeks.org/reverse-a-linked-list/" rel="nofollow noreferrer">this site.</a></p>
  
  <pre><code>void recursiveReverse(struct Node** head_ref)
  {
      struct Node* first;
      struct Node* rest;
  
      /* empty list */
      if (*head_ref == NULL)
         return;   
  
      /* suppose first = {1, 2, 3}, rest = {2, 3} */
      first = *head_ref;  
      rest  = first-&gt;next;
  
      /* List has only one node */
      if (rest == NULL)
         return;   
  
      /* reverse the rest list and put the first element at the end */
      recursiveReverse(&amp;rest);
      first-&gt;next-&gt;next  = first;  
  
      /* tricky step -- see the diagram */
      first-&gt;next  = NULL;          
  
      /* fix the head pointer */
      *head_ref = rest;              
  }
  </code></pre>
  
  <p>I dont understand why after the last recursive call the value of rest remains the same? I understand <em>recursiveReverse(&amp;rest)</em> is passing the actual address of rest,but isn't this address being taken by head_ref only? Which would mean that every recursive call has its own local copy of first and rest, and so <strong>*head_ref = rest</strong> shouldn't work because the value of rest would keep changing. </p>
  
  <p>Where is my understanding going wrong?</p>
  
  <p>Edit : Adding some of my scribbles.</p>
  
  <p><a href="https://i.stack.imgur.com/jT2Sm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jT2Sm.jpg" alt="enter image description here"></a></p>