C program to create singly linked list.

Posted by Mangesh on May 08, 2018

/* program to create a linked list */

Description :

Singly Link list
A singly link list's node is divided into twofield. The first field holds information about the node, and second field holds the reference of next node. When we link all node is some order then it becomes Singly Link list. In singly link list we have only one reference of next node, so in singly link list we can travels in only one way. The reference (link) points to the next node in the list, or to a null value( if its last node). For Singly Link list we need one Head reference to point to the First node of the list.

Program :

typedef struct node
  int data;
  struct node *next;
} node;
void display(node *list)
  printf("\nElements in linked list : ");
  while(list != NULL)
    printf("  %d",list->data);
    list = list->next;
void main()
  node *head, *tail;
  char character ='y';
  head = (node *) malloc (sizeof(node));
  tail = head;
  while(character == 'y'){
  printf("\nEnter the element value : ");
  printf("Do you want to add more element (y/n) : ");
    tail->next =  (node *) malloc(sizeof(node));
    tail = tail->next;

Output :

c program linked list Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program to create singly linked list.
2 C program to display elements of linked list in reverse order.
3 C program to count number of node in linked list.
4 C program to print a linked list in reverals order.
5 C program to search an element in linked list.
6 C for circular queue using linked list.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.