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.
精彩评论