可以說我有下面的代碼,指針指針,我如何獲取值?
typedef struct WordNode WordNode;
struct WordNode {
int freq; // The frequency of the the word.
char *word; // The word itself.
WordNode *next; // The next word node in the list.
};
struct WordSet {
int size; // The number of elements in the set.
WordNode *head; // The starting node in the set.
};
在此之後,我已經得到了一些函數初始化這些結構。爲了防止這篇文章中的代碼太多,我將避免在這裏發佈這些函數。
現在,可以說我有以下,
WordNode **p = wset->head; // can't change this line
這裏,P基本上是一個指針指向一個指針,正確嗎?
然後,如果我這樣做:
(*p) == NULL
如果p指向NULL這將返回true,對不對?
現在,我將如何獲取存儲在wset-> head中的單詞?
我可以這樣做嗎?
(*(*p))->word
如果我想讓p指向下一個WordNode,我可以這樣做嗎?
p = (*(*p))->next
我只是想知道,如果這一切都是有效的語法,以便我知道我正確使用指針。
'WordNode ** p = wset-> head;''>> >> WordNode ** p =&wset-> head; ''應該改變這個//順便說一句:什麼是'wset'? – joop
'WordNode ** p = wset-> head; '..compiler din't尖叫? –
'WordNode ** p = wset-> head; '不編譯,你不能將一個'WordNode *'賦值給一個'WordNode **'變量。也許你的意思是'WordNode ** p =&wset-> head; '? –