title: Display function in Circular Linked List in C
body: <p>I am having a problem with my Circular Linked list. I believe the problem is with my display function. Please let me know what is going wrong. The problem I have is that the first n-1 elements are displayed and then I get a segmentation fault(The last element doesn't get displayed and I get a segmentation fault).Thank you :-)</p>
  
  <pre><code>             #include&lt;stdio.h&gt;
               #include&lt;stdlib.h&gt;
               struct Node
               {
                int data;
                struct Node* link;
               };
               struct Node* last = NULL;
               void Insert_begin(int a)
               { 
                 struct Node* temp;
                 temp = malloc(sizeof(struct Node));
                 temp-&gt;data = a;    
                 if (last == NULL)
                   last = temp;
                 else
                 {
                  temp-&gt;link = last-&gt;link;
                  last-&gt;link = temp;
                 }
               }
               void Display()
               {   
                 struct Node* temp;    
                 if (last == NULL)
                 {
                   printf("list is empty");
                 }        
                 temp = last-&gt;link;
                 while(temp!=last)
                 {
                   printf("%d\n",temp-&gt;data);
                   temp = temp-&gt;link;     
                 }
                 printf("%d\n",temp-&gt;data);   
               }  
               int main()
               {
                Insert_begin(0);               
                Insert_begin(1);
                Insert_begin(2);
                Insert_begin(3);
                Insert_begin(4);
                Display();
                return 0;
               }
  </code></pre>