When we use Structure and pointer to implement linked list we use malloc
We are implementing Linked list using pointer, simply creating an pointer does not give it any memory
We want Memory to store some meaningful data in that pointer as well as information regarding pointers next to it
Eg:
struct node{
int data;
struct node *next;
}
Above code defines a node, i.e node will contain two parameters 1) data and 2) pointer to next node.
But while implementing it we must have some memory reserved for node: assuming int takes 2 byte and pointer to next node takes 2 byte
head=(struct node*)malloc(sizeof(struct node));
above line gives head 4 byte of space in Memory; now we can store a integer and pointer to next element of list in head node