問題描述
我已經看到一些代碼,以及我的編譯器生成的一些錯誤,這些錯誤在變量之前有一個 '**
' 標記(例如 **variablename unreferenced-- 或其他東西,我可以不記得完全是偶然的).我相當肯定這與指針有關,如果我不得不猜測它看起來像是試圖取消引用兩次.'**
' 是相當無法谷歌的.有人可以給我指出一個好的網站/文檔,還是有人愿意在這里解釋一下?
I've seen some code, as well as some errors generated from my compiler that have a '**
' token before the variable (eg **variablename unreferenced-- or something, I can't recall exactly offhand). I'm fairly certain this is related to pointers, if I had to guess it looks like it's trying to dereference twice. '**
' is fairly ungoogleable. Can someone point me to a good website/documentation or would someone care to explain it here?
謝謝.
很好的回應.如果我可以添加,在哪些情況下使用指向指針的指針是有用的?難道您不應該只使用原始指針而不是創建另一個指向原始指針的指針嗎?
Great responses. If I can add, what would be some situations where it is useful to have a pointer to a pointer? Shouldn't you just be using the original pointer instead of creating yet another pointer to the original pointer?
推薦答案
**
實際上不僅是指向指針的指針(如在聲明中),而且還是一個解引用的解引用(在一個聲明).
**
is not actually only pointer to pointer (as in declaration), but is also the dereference of a dereference (in a statement).
它經常在沒有 & 的 C 中使用.參考符號,例如更新一個指針類型的返回值:
It is used often in C which does not have the & notation for references, e.g. to update a return value which is a pointer type:
int alloc_foo(struct foo **foo_ret)
{
*foo_ret = malloc(sizeof(struct foo));
return 1; /* to indicate success; return value in foo_ret */
}
這篇關于C++中的**是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!