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
意味着什么。
确定,所以从顶部,是一个指向结构,而在这个函数中,参数是一个指针,它是指针的引用地址? – silent 2010-04-24 00:56:02
不,'listpointer'只是对'A'的引用。请参阅我答案中的链接。也就是说,当你改变'listpointer'时,你确实正在改变'A'。这是一个别名。 – 2010-04-24 00:59:46
哦,我明白了,所以'*'实际上就是指针。不是尊敬的运营商 – silent 2010-04-24 01:03:22