0

I have the following code

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.

1 Answer 1

2

Node * &foo is a reference to a Node *

So when you call it with

AddNode(A, 123, 99.87);

it will change A.

Sign up to request clarification or add additional context in comments.

3 Comments

ok so from the top, A is a pointer to a structure, and in this function the argument is a pointer which is the deferenced address of a the pointer?
No, listpointer is just a reference to A. See the link in my answer. I.e., when you change listpointer, you're really changing A. It's an alias.
oh I see, so the '*' is actually acting as the pointer here. not the deference operator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.