g++提示“段错误 (核心已转储)”的问题

2025-02-23 10:00:03
推荐回答(1个)
回答1:

node *head,*p,*rear;
rear=head->next;

head 没有申请内存,所以 head->next 是错误的,属于野指针。
head = (node*)malloc(sizeof(node));

其他涉及到node 的地方都要申请内存。