title: C++ Creating a linked list using recursive function
body: <p>Hi I am a beginner learning c++
  I am trying to create a linked list using recursive function
  I though I got more or less pointer, linked list, data structure etc but I am stuck for 2 days.</p>
  
  <p>Here's my entire code.</p>
  
  <p>What I am basically trying to do is like I said creating a linked list using only recursive function.
  The problem is my pointer variable 'head' is always pointing to NULL and I can't figure out why and i guess i misunderstood a lot of things but i simply don't know what ... and more i try more i am getting confused.</p>
  
  <p>It must be quite newbie question but Id really appreciate if someone can help me.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  struct linkedlist
  {
      int value;
      linkedlist *next;
  };
  
  void insertNode(linkedlist* temp)
  {
      if (temp-&gt;next != NULL)
      {
          insertNode(temp-&gt;next);
      }
      else
      {
          temp-&gt;next = new linkedlist;
          temp-&gt;next-&gt;value = 0;
          temp-&gt;next-&gt;next = NULL;
      }
  
  }
  
  
  linkedlist *addNode(linkedlist *temp)
  { 
      if (temp == NULL)
      {
          linkedlist *newelement = new linkedlist;
          newelement-&gt;value = 0;
          newelement-&gt;next = NULL;
          temp = newelement;
  
          return newelement;
      }
      else
      {
          insertNode(temp);
      }
  }
  
  void displaylist(linkedlist *temp)
  {
      while (temp != NULL)
      {
          cout &lt;&lt; temp-&gt;value &lt;&lt; endl;
          temp = temp-&gt;next;
      }
  }
  
  int main()
  {
      linkedlist *head = NULL;
  
      linkedlist *element1 = addNode(head);
      linkedlist *element2 = addNode(head);
      linkedlist *element3 = addNode(head);
      linkedlist *element4 = addNode(head);
      linkedlist *element5 = addNode(head);
  
      cin.ignore();
      cin.get();
  }
  </code></pre>