I am learning link list through book and in one book head pointer is initialised globally and in another its initialised within main and then passed to create. Is there any advantage of declaring it in main.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void create(void);
void traverse(void);
void create()
{
char ch;
struct node *ptr,*cpt;
ptr=(struct node*) malloc(sizeof(struct node));
if(ptr==NULL)
{
printf("Memory cant be allocated");
}
printf("Enter information you want to store in node.\n");
scanf("%d",&ptr->info);
first=ptr;
do
{
cpt=(struct node*) malloc(sizeof(struct node));
if (cpt==NULL)
printf("Can't allocate memory");
printf("Enter next node information.");
scanf("%d", &cpt->info);
ptr->link=cpt;
ptr=cpt;
printf("Do you want to enter another node?(y/n)");
ch=getch();
}while(ch=='y');
ptr->link = NULL;
}