单链表问题
程序代码:
//define struct type typedef struct Lnode { int data; struct LNode* next; }Lnode; //creat Link list void CreatList() { //creat Head pointer and Tail pointer Lnode** Head; Lnode* Tail; //creat an empyt Link list *Head = (Lnode* )malloc(sizeof(Lnode)); (*Head)->next = NULL; Tail = *Head; //insert data for (int i = 0; i < 3; ++i) { //creat new node Lnode* P = (Lnode* )malloc(sizeof(Lnode)); //update date domain and pointer domain of new node P->data = i; P->next = NULL; //update pointer domain of before node Tail->next = P; //update Tail pointer Location Tail = P; } }
gcc 9.2.0 报错
.\Link.c: In function 'CreatList': .\Link.c:45:20: warning: assignment to 'struct LNode *' from incompatible pointer type 'Lnode *' {aka 'struct Lnode *'} [-Wincompatible-pointer-types] 45 | Tail->next = P; | ^
我觉得没错啊 Tail->next 与 P 都是 Lnode* 类型啊