首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >链接列表中node、&node和node->next的区别

链接列表中node、&node和node->next的区别
EN

Stack Overflow用户
提问于 2014-09-18 04:53:04
回答 2查看 1.2K关注 0票数 0
代码语言:javascript
复制
// Program to insert node at front in linked list.

//这是一个简单的链表程序,但是我不明白& newNode,newNode和newNode的//值的区别->next

代码语言:javascript
复制
void PushAtFrontLinkList(int value)
{
    if(head==NULL)
    {

        head=tail;
    }
    node* newNode=new node();
    newNode->data=value;
    newNode->next=head; 
    head=newNode;


    // Trying to differentiate between data contained in newNode and &newNode and newNode->next
    cout<<"just new node"<<newNode<<endl; // what will be contained in newNode?     cout<<"address of node"<<&newNode<<endl; // what will be contained in &newNode?  
    cout<<"new node next"<<newNode->next<<endl; // It will be the address of the next node?


}
EN

回答 2

Stack Overflow用户

发布于 2014-09-18 06:00:39

newNode将包含您刚刚创建的新节点对象的地址。对于newNode-> next,它包含列表中下一个节点的地址。

请注意,在最后,newNode将是列表的头部,并且newNode->next将指向旧的头部。

票数 1
EN

Stack Overflow用户

发布于 2014-09-18 05:58:59

&newNode:节点在内存中的地址newNode:要操作newNode的节点-> next :下一个节点*指针。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25900158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档