• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

c语言链表里面有一些概念不清楚,求大神给我讲讲

有点不明白链表里面的
struct node *head=(struct node*)malloc(sizeof(struct node));
struct node *ptail;
head=ptail;
这个是什么意思,让ptail指向head节点吗?
struct node *head=(struct node*)malloc(sizeof(struct node));
struct node *ptail=(struct node*)malloc(sizeof(struct node));
head=ptail;
那么这个又是什么意思呢?
还有 struct node *head=(struct node*)malloc(sizeof(struct node));
struct node *ptail;
*pnew=(struct node*)malloc(sizeof(struct node));
head=ptail;
ptail->next=pnew
相当于head->next=pnew吗?

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

第一部分

struct node *head=(struct node*)malloc(sizeof(struct node));
这句话的意思是说:定义一个大小为struct node的内存空间,这个内存空间的首地址将储存在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大小的内存空间给指针变量head和ptail
head=ptail;
同理,让head指向ptail


第三部分
struct node *head=(struct node*)malloc(sizeof(struct node));
分配struct node大小的内存空间给指针变量head
struct node *ptail;
声明指针变量ptail
*pnew=(struct node*)malloc(sizeof(struct node));
分配struct node大小的内存空间给指针变量pnew
head=ptail;
让head指向ptail
ptail->next=pnew
将指针pnew所指向的内存空间的首地址,储存在ptail的next元素中
这个操作相当于head->next=pnew,但并不是随时都如此,只有在head和ptail指向同一个内存空间时才是这样

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!