我不明白爲什麼t->next
指向的地址不是t
。如果t->next
指針等於n
的地址,並且t
指針等於t->next
的地址爲什麼t->next
似乎指向不同的地址?我被困在這裏。指向一個地址的指針我沒想到
struct Node {
int data;
Node* next;
};
int main() {
Node* n;
Node* t;
Node* h;
n = new Node;
t = new Node;
n->data = 2;
t->next = n;
t = t->next;
cout << n << "\n" << n->data << "\n" << t << "\n" << t->next << endl;
}
輸出:
0x7a11c8 2 0x7a11c8 0x65685372
您沒有初始化'n-> next'。 –