C++ 指针和参考问题(链表)
我有以下代码C++ 指针和参考问题(链表),c++,pointers,reference,linked-list,C++,Pointers,Reference,Linked List,我有以下代码 struct Node { int accnumber; float balance; Node *next; }; Node *A, *B; int main() { A = NULL; B = NULL; AddNode(A, 123, 99.87); AddNode(B, 789, 52.64); etc… } void AddNode(Node * & listpointer, int a, float b) { // ad
struct Node {
int accnumber;
float balance;
Node *next;
};
Node *A, *B;
int main() {
A = NULL;
B = NULL;
AddNode(A, 123, 99.87);
AddNode(B, 789, 52.64);
etc…
}
void AddNode(Node * & listpointer, int a, float b) {
// add a new node to the FRONT of the list
Node *temp;
temp = new Node;
temp->accnumber = a;
temp->balance = b;
temp->next = listpointer;
listpointer = temp;
}
在这里,
void AddNode(Node*&listpointer,int a,float b){
什么是*&listpointer
的确切含义。Node*&foo
是a到a的节点*
所以当你用
AddNode(A, 123, 99.87);
它将更改A。好的,因此从顶部开始,A是指向结构的指针,在这个函数中,参数是指针,它是指针的延迟地址?不,
listpointer
只是对A
的引用。请参阅我答案中的链接。也就是说,当您更改listpointer
时,您实际上是在更改Ae> 。这是一个别名。哦,我明白了,所以“*”实际上在这里充当指针。而不是尊重运算符