title: Difference between linked list traversal **while(thead != NULL)** and while(thead->next !=NULL)
body: <p>Can anyone tell me what is the difference between <strong>while(thead != NULL)</strong> and <strong>while(thead->next !=NULL)</strong> because for traversing the list <strong>thead != NULL</strong> is not working while <strong>thead->next</strong> works. 
  According to my understanding head node is just a pointer to the starting node and not the the starting node itself.<br>
  <a href="https://i.stack.imgur.com/2oRQD.png" rel="nofollow noreferrer">See this if u have doubt</a>.Here head just stores address.</p>
  
  <p>//thead means temp head variable to store the address head points to.<br>
  This is the code for insertion.         </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;malloc.h&gt;
  #include&lt;stdlib.h&gt;
  
  struct node
  {
      int data;
      struct node *next;
  };
  struct node *head;
  void insert(int x)
  {
      struct node *temp=(struct node *)malloc(sizeof(struct node));   
      temp-&gt;data=x;   
      temp-&gt;next=NULL;   
      if(head==NULL)     
      {     
           head=temp;    
      }
      else
      {
          struct node * thead;
          thead=head;  
          while(thead-&gt;next!=NULL)
          {
              thead=thead-&gt;next;  
          }
          thead-&gt;next=temp;
      }
  }
  
  void print()
  {
      struct node *temp;
      temp=head;
      while(temp!=NULL)
      {
  
          printf("%d",temp-&gt;data);
              temp=temp-&gt;next;
      }
  }
  int main()
  {
      head=NULL;
      int i,n,x;
      printf("enter number of nodes");
      scanf("%d",&amp;n);
      for(i=0;i&lt;n;i++)
      {
          printf("enter no");
          scanf("%d",&amp;x);
          insert(x);
      }
      print();
  }
  </code></pre>
  
  <p><strong>If we replace thead ->next != NULL by thead !=NULL then dev c++ stops working.Vice versa happens in the printf for traversal ...</strong> </p>
  
  <p>So can someone answer the difference between the above two?     </p>
  
  <p>Also,Is head node the first node which contains both data and address or does it just stores addresses like in the diagram above?    </p>
  
  <p>Also if the head node is only a pointer which stores address then how are we able access thead->next ?     </p>
  
  <p>And when is a pointer to a structure NULL?     </p>
  
  <p>Thanks</p>