Consider the error in following program-
#include<stdio.h>
#include<conio.h>
#define MAX 100
struct stacktype
{
int stack[MAX];
int top;
}
;
void push(struct stacktype * s,int item)
{
if(s->top==MAX-1)
{
printf("Overflow");
return;
}
s->top++;
s->stack[s->top]=item;
}
int pop(struct stacktype *s)
{
int item;
if(s->top==-1)
{
printf("UnderFlow");
return -1;
}
item=s->stack[s->top];
s->top--;
return item;
}
Though I know the fault that pointers are being passed by value.. but don't understand that when i pass s1(pointer), the address of the structure being pointed to should get copied to s.. and then changing s->top should also change s1's top.. (both pointing to same structure).. Please clarify I am a bit confused..