Pointer address does not change in a link list
问题 My problem is q->next always prints the same address, but I assigned q = &x; . Why it is not printing different addresses? #include <stdio.h> class Node { public: int val; Node *next; Node(int v,Node *p) { val=v, next=p; } }; int main() { Node head(0, NULL); Node *q = &head; int i = 5; while (i>0) { Node x(i * 10, q); q = &x; printf("# %d %p\n", q->val, q->next); i--; } } 回答1: This has to do with the way x is allocated: It is a local variable inside the main function. That means it is