title: Printing Linked List in C++
body: <p>My following code print just  only first element. In <code>print_list()</code> function, it stops after printing first element. It says after first element, <code>head-&gt;next</code> is <code>0</code>. Shouldn't point towards second element?  </p>
  
  <p>I want to simply print whole list.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdlib&gt;
  using namespace std;    
  struct node {
    int x;
    node *next;
  };    
  node* add_element(node*);
  bool is_empty(node*);
  void print_list(node*);
  node* search(node*);
  
  int main()
  {
      node *head;
      head=NULL;
      node* current=head;
      for(int i=0;i&lt;5;i=i+1)
      {
         if (current==NULL)
         { 
           current=add_element(current);
           head=current;
         }
         else{ 
            current=add_element(current);
         }
       }
       cout&lt;&lt;head-&gt;next&lt;&lt;endl;
  
       // DOUBT: head-&gt;next gives NULL value. It should give me pointer to 2nd node
       print_list(head);
  }     
  node* add_element(node* current)
  {   
      node* temp;
      temp=new node;
      temp-&gt;next=NULL;
      cout&lt;&lt;"enter element"&lt;&lt;endl;
      cin&gt;&gt;temp-&gt;x;
      current=temp;
      return current; 
  }      
  bool is_empty(node* temp)
  {
      return temp==NULL;      
  }    
  void print_list(node* temp)
  {
      if (is_empty(temp)==false)
      {   
           cout&lt;&lt;"here temp(head)"&lt;&lt;temp-&gt;next&lt;&lt;endl;
           while(temp!=NULL)
           {
              cout&lt;&lt;temp-&gt;x&lt;&lt;endl;
              temp = temp-&gt;next;
           }
      }
  }
  </code></pre>