Program A
void create(struct Stack *st)
{
printf("Enter Size");
scanf("%d",&st->size);
st->top=-1;
st->S=(int *)malloc(st->size*sizeof(int));
}
int main()
{
struct stack st;
create(&st);
return 0;
}
Program B - for program B assume that a linked list has been created with first(declared as a global variable) pointing at the 1st node in the list.
struct Node
{
int data;
struct Node *next;
}*first=NULL;
void display(struct Node *p)
{
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
int main()
{
display(first);
return 0;
}
My doubt is, why in program A while calling the create function, the & operator is required and why in program B it is not used while calling display function. Both create and display function take pointer as argument. Can you explain the relationship between & and * operator while calling a function with examples. Thanks in advance.