#include <stdio.h>
#define x 10
struct data
{
int num;
int state;
};
struct queue
{
struct data *q1[x];
int num;
};
struct queue *q;
void insert(struct queue *q, struct data *d)
{
d->state = 0;
q->q1[0] = d;
q->num = 1;
}
int main()
{
struct data *d;
// struct queue *q = (queue*)malloc(sizeof(struct queue));
insert(q, d);
printf("%d\n %d\n", q->q1[0]->state, q->num);
}
I wrote the code like this. And it caused segmentation fault (core dumped). I wonder why it is happened and how should I edit it.
Thank you.