title: Why does my C++ code show segmentation fault in the following snippet of printing a linked list?
body: <p>I have this question  where i have to write a function for printing the full linked list. Could you explain why am I getting this error and how to fix it </p>
  
  <pre><code>/*
         Print elements of a linked list on console 
         head pointer input could be NULL as well for empty list
         Node is defined as 
         struct Node
       {
          int data;
          struct Node *next;
       }
     */
       void Print(Node *head)
       {
       cout&lt;&lt;"test";
       while(head-&gt;next!=NULL)
       {
  
           cout&lt;&lt;(head-&gt;data)&lt;&lt;endl;
           head=head-&gt;next;
  
       }
  
     }
  </code></pre>
  
  <p>?</p>