开发者

pointer and reference question (linked lists)

开发者 https://www.devze.com 2022-12-27 19:45 出处:网络
I have the following code 开发者_Python百科struct Node { int accnumber; float balance; Node *next; };

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

精彩评论

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

关注公众号