I am studying how to insert node at the beginning and I came through this code which I am unable to understand.
I am not getting the print function .
typedef struct node
{
int data;
struct node *next;
} Node;
Node *head;
void insert(int x)
{
Node *temp=(Node*)malloc(sizeof(Node));
temp->data=x;
temp->next=head;
head=temp;
}
void print()
{
Node *temp=head;
printf("List is:");
while(temp!=NULL) //Unable to understand this statement as how will the loop terminate?
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}