开发者

pointer and reference question (linked lists)

I have the following code

开发者_Python百科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;
}

in this here void AddNode(Node * & listpointer, int a, float b) { what does *& listpointer mean exactly.


Node * &foo is a reference to a Node *

So when you call it with

AddNode(A, 123, 99.87);

it will change A.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜