可以说我有下面的代码,指针指针,我如何获取值?
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; '? –