-1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    int* queue;
    int front, rear, size;
} queueType;

void init_queue(queueType* q, int size){
    int i;

    q->queue = (int*)malloc(size * sizeof(int));

    for (i = 0;i < size;i++) q->queue[i] = 0;

    q->size = size;
    q->front = 0;
    q->rear = 0;    
}

int main() {   
    int size;
    int n;
    char com;
    int val;

    scanf("%d", &size);
    getchar();
    scanf("%d", &n);
    getchar();

    queueType* q = NULL;
    init_queue(q, size);
    
    printf("%d", q->queue[0]);
}

// init function can't run 
meaning-matters
  • 19,878
  • 9
  • 76
  • 125
dnssup
  • 1
  • 1
  • You never allocate room for the `queueType` itself so `q->queue` is accessing invalid memory. – Lundin May 12 '22 at 09:06

0 Answers0