struct stack_type
{
int content;
struct stack_type *next;
};
typedef struct stack_top
{
struct stack_top *top;
}*Stack;
//Case 1:
void display(Stack s)//Works perfectly
{
struct stack_type *a;
a=s->top;
while(a!=NULL)
{
printf("%d ",a->content);
a=a->next;
}
}
//Case 2:
void display(Stack s)
{
struct stack_type *a;
a=s->top;
while(s->top!=NULL)//Infinite loop
{
printf("%d ",a->content);
s->top=a->next;
}
}
Can anyone explain me why this is happening?