我定义了学生数据和单链表结构体,随后在初始化链表的函数里面判断是否成功为节点申请空间,可是编译器报错!对于struct非法,这是为什么呢?
//图书结构体
struct student {
char studentName[20];
long studentId;
char studentClass[40];
};
//单链表结构体
struct node {
struct student data;
struct node* next;
};
//初始化单链表
int initList(struct node* list) {
list = (struct node*)malloc(sizeof(struct node));
if (!(*list))exit(OVERFLOW);
}
报错信息:
!(*list)是要干啥,为什么要对list进行取反
如果你是想判断它不为空,那把==改成!=就行了,别乱写逻辑啊
int initList(struct node **list) //需要双指针。
{
*list = (struct node *)malloc(sizeof(struct node));
if (!(*list)) exit(OVERFLOW);
}