title: Get node value in linkedlist from end in c
body: <p>I am doing this hackerrank question (<a href="https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail</a>)
  My code is as follows -</p>
  
  <pre><code>int GetNode(Node *head,int positionFromTail)
  {
    Node *prev = NULL;
    Node *current = head;
    Node *next;
    while(current!=NULL){
       next = current-&gt;next;
       current-&gt;next = prev;
       prev = current;
       current = next;
    }
    head = prev;
    int p=0;
    while(head-&gt;next!=NULL){
      if(p== positionFromTail){
          return head-&gt;data;
      }
      else {
          p++;
          head= head-&gt;next;
      }
    } 
  }
  </code></pre>
  
  <p>So what i have done is, I have first reversed the linkedlist and then looped for the specific position and then printed its value. Is it correct method to do it?
  It gives me this error.</p>
  
  <pre><code>  solution.cc: In function ‘int GetNode(Node*, int)’:
    solution.cc:42:1: error: control reaches end of non-void function [Werror=return-type]
     }
     ^
     cc1plus: some warnings being treated as errors
  </code></pre>