为什么程序会崩溃?虽然有时它没有。我使用的是visual studio 2017.我使用在线编译器运行我的整个程序(更多功能)并且它不会崩溃。谢谢。 [ 1 [] 2
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node* next;
}node;
typedef struct {
int count;
node *front;
node *rear;
}QueueHead;
QueueHead *CreateQueue(){
QueueHead *myQH = (QueueHead*)malloc(sizeof(myQH));
//Empty list is created.
//Emelent counter is set to zero
myQH->count = 0;
//Top should address NULL as it is an empty list
myQH->front = NULL;
myQH->rear = NULL;
return myQH;
}
int main() {
QueueHead *myQH = CreateQueue();
}
答案 0 :(得分:0)
尝试更改代码行
QueueHead *myQH = (QueueHead*)malloc(sizeof(myQH));
到
QueueHead *myQH = (QueueHead*)malloc(sizeof(QueueHead));