title: segmentation fault 11 during a circular linked list node addition at the beginning of the list
body: <p>When I created the program at first I could create the circular linked list with addition of only the first initial node.</p>
  
  <p>As soon as I try to add the new node at the beginning then it gives me a Segmentation Fault 11.</p>
  
  <p>I even tried to search Stack Overflow for this problem but many of them have just dereferenced the pointer variable.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  struct node
  {
      int data;
      struct node *next;
  };
  
  struct node *start=NULL;
  struct node *create_cll(struct node *);
  struct node *display(struct node *);
  struct node *add_beg(struct node *);
  struct node *add_end(struct node *);
  struct node *del_beg(struct node *);
  struct node *del_end(struct node *);
  struct node *del_aftgiven(struct node *);
  struct node *del_entire(struct node *);
  
  int main()
  {
      int option;
      do
      {
          printf("\n\n****MAIN MENU****");
          printf("\n\nEnter an option from the list given below");
          printf("\n1. Create a linked list");
          printf("\n2. Display the linked list");
          printf("\n3. Add a node at the beginning of the list");
          printf("\n4. Add a node at the end of the list");
          printf("\n5. Delete a node from the beginning of the list");
          printf("\n6. Delete a node from the ending of the list");
          printf("\n7. Delete a node after a given node");
          printf("\n8. Delete the entire linked list");
          printf("\n");
          scanf("%d",&amp;option);
  
          switch(option)
          {
              case 1: start = create_cll(start);
                      printf("\nCircular linked list created!");
                      break;
  
              case 2: start = display(start);
                      break;
  
              case 3: start = add_beg(start);
                      break;
  
          }
      }while(option!=4);
      return 0;
  }
  
  struct node *create_cll(struct node *start)
  {
      struct node *new_node,*ptr;
      int num;
      printf("\nEnter -1 to stop adding new nodes");
      printf("\nEnter the data:");
      scanf("%d",&amp;num);
      if(num!=-1)
      {
          new_node=(struct node *)malloc(sizeof(struct node));
          new_node-&gt;data=num;
          if(start!=NULL)
          {
              while(ptr-&gt;next!=start)
              {
                  ptr=ptr-&gt;next;
              }
              ptr-&gt;next=new_node;
              new_node-&gt;next=start;
          }
          else
          {
              new_node-&gt;next=new_node;
              start=new_node;
          }
      }
      return start;
  }
  
  struct node *display(struct node *start)
  {
      struct node *ptr;
      ptr=start;
      while(ptr-&gt;next!=start)
      {
          printf("\t %d",ptr-&gt;data);
          ptr=ptr-&gt;next;
      }
      printf("\t %d",ptr-&gt;data);
      return start;
  }
  
  struct node *add_beg(struct node *start)
  {
      struct node *ptr,*new_node;
      int num;
      printf("\nEnter the data you want to enter at the beginning:");
      scanf("%d",&amp;num);
      new_node=(struct node *)malloc(sizeof(struct node));
      new_node-&gt;data=num;
      if(ptr-&gt;next!=start)
      {
          ptr=ptr-&gt;next;
      }
      ptr-&gt;next=new_node;
      new_node-&gt;next=start;
      start=new_node;
      printf("Node succesfully added:");
      return start;
  }
  </code></pre>