一运行就死
#include
#include
typedef struct student_
{
char id[9];
int a;
int b;
struct student_ *next;
}Node;
int main()
{
Node list1;
Node *list2;
list1 = (Node)malloc(sizeof(sizeof(Node)));
list2 = (Node*)malloc(sizeof(sizeof(Node)));
list1->next = NULL;
list2->next = NULL;
free(list1);
free(list2);
return 0;
}
sizeof(sizeof(Node)) 的意思是将 sizeof(Node) 的结果 (int 类型) 取数据类型大小,结果等于 sizeof(int) ,显然是不对的,应该改成 sizeof(Node) 。
#include <stdio.h>
#include <stdlib.h>
typedef struct student_
{
char id[9];
int a;
int b;
struct student_ *next;
}Node;
int main()
{
Node *list1;
Node *list2;
list1 = (Node*)malloc(sizeof(Node));
list2 = (Node*)malloc(sizeof(Node));
list1->next = NULL;
list2->next = NULL;
free(list1);
free(list2);
return 0;
}