【发布时间】:2017-01-26 23:06:27
【问题描述】:
我不明白为什么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。
标签: c++ list pointers struct memory-address