Here is my code:
struct queue {
int queue_arr[5];
int rear;
int front;
};
int main()
{
struct queue q;
int choice;
queue_init(q);
}
queue_init(struct queue *q)
{
int i = 0;
q->rear = -1;
q->front = -1;
for (; i < MAX; i++) {
q->queue_arr[i] = 0;
}
}
It causes segmentation error on execution:
[root@workmachine test_cpp]# ./queue Segmentation fault (core dumped)
If I remove struct I’ll use int queue_arr[5]; int rear; int front; as global segmentation error disappears. Why? and how to to avoid it whit using of structs?
You should pass the address:
I’m surprised it compiles as it stands.