指针和引用问题(链表)

时间:2010-04-24 00:49:05

标签: 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) {
// 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完全是什么意思。

1 个答案:

答案 0 :(得分:2)

Node * &fooreferenceNode *

所以当你用

打电话时
AddNode(A, 123, 99.87);

它将改变A。