C++ 节点之间的差异,&;节点和节点->;链接列表中的下一个

C++ 节点之间的差异,&;节点和节点->;链接列表中的下一个,c++,pointers,linked-list,C++,Pointers,Linked List,//这是一个简单的链表程序,但我不明白两者之间的区别 //newNode、newNode和newNode的值->下一步 // Program to insert node at front in linked list. void PushAtFrontLinkList(int值) { if(head==NULL) { 头=尾; } node*newNode=newNode(); 新建节点->数据=值; 新建节点->下一步=头部; 头=新节点; //尝试区分newNode和&newNode中包

//这是一个简单的链表程序,但我不明白两者之间的区别 //newNode、newNode和newNode的值->下一步

// Program to insert node at front in linked list.
void PushAtFrontLinkList(int值)
{
if(head==NULL)
{
头=尾;
}
node*newNode=newNode();
新建节点->数据=值;
新建节点->下一步=头部;
头=新节点;
//尝试区分newNode和&newNode中包含的数据以及newNode->next

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

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


请注意,在最后,newNode将是列表的标题,newNode->next将指向旧标题。

它们分别是指向
node*
、指向
node
和指向
node
的指针。这是否意味着newNode应该包含与newNode->next中包含的地址相同的地址?简而言之,newNode将包含某些地址或它将只包含节点的结构。它们应该是不同的。但是在使用指针时可能会发生任何情况,或者您打算使其处于初始状态。@hustmphrr另外,newNode包含自身的地址?newNode->next包含下一个节点的地址?newNode包含您刚刚“新建”的节点.next包含下一个节点,如果您以正确的方式操作指针。谢谢。但是&newNode包含什么?如果我想将newNode的地址传递给其他函数(通过引用传递),那么将传递类似函数(newNode)或函数(&newNode)?您将使用
函数(newNode)
。这是因为
newNode
已经是一个地址。请注意,您将其声明为
node*newNode
。类型
node*
(末尾带有星号)用于声明一个变量,该变量仅包含
node
类型变量的地址,即它只是一个指针。
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?


}