转帖原文 http://coolshell.cn/articles/8990.html
自己备忘和测试下
typedef struct node{ struct node* next; } node; void test(node** head){ node** curr = head; node* entry = *curr; printf("curr:%p,*curr:%p\r\n",curr,(*curr)); printf("entry:%p,entry->next:%p\r\n",entry,(entry->next)); *curr = entry->next; printf("curr:%p,*curr:%p\r\n",curr,(*curr)); printf("entry:%p,entry->next:%p\r\n",entry,(entry->next)); printf("-------------------------\r\n"); *curr = entry; curr = &entry->next; printf("curr:%p,*curr:%p\r\n",curr,(*curr)); printf("entry:%p,entry->next:%p\r\n",entry,(entry->next)); } int main(){ node* head = (node*)malloc(sizeof(struct node)); head->next = (node*)malloc(sizeof(struct node)); head->next->next = (node*)malloc(sizeof(struct node)); printf("head:%p,&head:%p,head->next:%p,&head->next:%p\r\n",head,&head,(head->next),(&head->next)); test(&head); printf("head:%p,&head:%p,head->next:%p,&head->next:%p\r\n",head,&head,(head->next),(&head->next)); return -1; }
next指针在结构的第一项的链表就是个双重指针不会因为编译器的不同而产生差异。