Sorry for such a noob question When I am declaring a struct and giving it size 80 it's giving segmentation fault.T tried resources but could'nt understand the mistake and the error is also not giving me any more details.... here is my code -
#include <stdio.h>
#include <stdlib.h>
struct stack
{
int size;
int top;
int *arr;
};
int isEmpty(struct stack *ptr)
{
if (ptr->top == -1)
{
return 1;
}
else
{
return 0;
}
}
int isfull(struct stack *ptr)
{
if (ptr->top == (ptr->size - 1))
{
return 1;
}
return 0;
}
int main()
{
printf("Test\n");
struct stack *s;
s->size = 80; //segmentation error occurs here
printf("Test\n");
s->top = -1;
s->arr = (int *)malloc(s->size * sizeof(int));
// printf("Test\n");
printf("%d",isEmpty(s));
if (isEmpty(s))
{
printf("stack is empty");
}
else
{
printf("Not empty");
}
return 0;
}
when I am declaring size 80 of struct s it's giving segmentation error and I don't know why
Thanks in advance