3 回答

TA貢獻4條經(jīng)驗 獲得超0個贊
第一部分
?struct node *head=(struct node*)malloc(sizeof(struct node));?
這句話的意思是說:定義一個大小為struct node的內(nèi)存空間,這個內(nèi)存空間的首地址將儲存在struct node類型的指針變量head中
struct node *ptail;?
定義一個struct node類型的指針變量ptail
head=ptail;
將ptail賦值給head,也可以說是讓head指向ptail
第二部分
?struct node *head=(struct node*)malloc(sizeof(struct node));
?struct node *ptail=(struct node*)malloc(sizeof(struct node));?
這兩句話的意思是:分別分配兩塊struct node大小的內(nèi)存空間給指針變量head和ptail
head=ptail;
同理,讓head指向ptail
第三部分
?struct node *head=(struct node*)malloc(sizeof(struct node));
分配struct node大小的內(nèi)存空間給指針變量head
?struct node *ptail;
聲明指針變量ptail
*pnew=(struct node*)malloc(sizeof(struct node));
分配struct node大小的內(nèi)存空間給指針變量pnew?
head=ptail;?
讓head指向ptail
ptail->next=pnew
將指針pnew所指向的內(nèi)存空間的首地址,儲存在ptail的next元素中
這個操作相當(dāng)于head->next=pnew,但并不是隨時都如此,只有在head和ptail指向同一個內(nèi)存空間時才是這樣
- 3 回答
- 0 關(guān)注
- 1027 瀏覽
添加回答
舉報