我一直遇到很多鏈接列表函數和C函數,它們打算傳遞雙指針來代替指向函數的單指針。例如下面的函數用於鏈表中的排序插入:作爲函數參數的雙指針
void sortedinsert(struct node **headref,struct node *newnode)
{
while(*headref!=NULL&&(*headref)->data<newnode->data)
headref=&((*headref)->next);
newnode->next=headref;
*headref=newnode;
}
請給我解釋一下關於地方單一指針使用雙指針作爲函數參數的,它是如何簡化了書寫功能上面鏈表?
我不知道你在問什麼。你能以問題的形式來說這個嗎? – BlackVegetable
http://c-faq.com/ptrs/passptrinit.html – hmjd
在C參數中按值傳遞。當你傳遞一個指針時,只傳遞指針的一個副本。所以如果你想改變調用者的原始指針,就會傳遞一個雙指針。 –