2010-04-24 67 views
0

我有以下代码指针和引用的问题(链表)

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意味着什么。

回答

2

Node * &fooreferenceNode *

所以,当你与

AddNode(A, 123, 99.87); 

叫它它会改变A.

+0

确定,所以从顶部,是一个指向结构,而在这个函数中,参数是一个指针,它是指针的引用地址? – silent 2010-04-24 00:56:02

+0

不,'listpointer'只是对'A'的引用。请参阅我答案中的链接。也就是说,当你改变'listpointer'时,你确实正在改变'A'。这是一个别名。 – 2010-04-24 00:59:46

+0

哦,我明白了,所以'*'实际上就是指针。不是尊敬的运营商 – silent 2010-04-24 01:03:22