Skip to content
Home » Creating a node in a single linked list

Creating a node in a single linked list

A node contains data and address of next node and the last node contains address as NULL.

Below is the code to create a single node in singly linked list.

#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *head;
int main(){
head=malloc(sizeof(struct node));
head->data=45;
head->next=NULL;
printf("%d",head->data);
}

OUTPUT:

45