title: Reverse a linked list using recursion technique in C
body: <p>I have the following C code which returns the reverse of a linked list. </p>
  
  <p>Though it reverses the linked list, I never get the head of the reversed linked list because the <code>restofElements</code> node is getting overwritten.  </p>
  
  <pre><code>S *reverseRecursive(S *headref) {
      S *firstElement   = NULL;
      S *restOfElements = NULL;
  
      if (headref==NULL) {
          return ;
      }
  
      firstElement = headref;
      restOfElements = headref-&gt;next;
  
      if (restOfElements == NULL)
          return headref;   
  
      reverseRecursive(restOfElements);    
      firstElement-&gt;next-&gt;next  = firstElement;
      firstElement-&gt;next  = NULL;          
      headref = restOfElements; 
  
      return headref; 
  } 
  </code></pre>
  
  <p>How can I get the head of the reversed linked list node returned to the calling program?</p>