Next 指向另一个 struct Node 但声明在 struct Node 之外的指针

Next pointer to another struct Node but declared outside of struct Node

我想创建一个指向结构的指针,该结构指向动态分配的结构的下一个节点,通常我们在结构中放置一个与结构相同类型的指针'*pnext',在我的例子中是什么我想做的是将 next 指针指向一个结构,在结构本身之外,例如在 main 中,并用在同一函数中声明的另一个指针指向该指针,我应该怎么做,这是可能的要做吗?

如果你不明白我的想法,下面是它应该是什么样子的概览:

struct Node{
int data;
};

int main(){
 struct Node *new_node;
 struct Node *next;

 new_node = malloc(sizeof(*new_node));
 new_node->data=2;

 new_node->next = malloc(sizeof(*new_node));
 new_node->next->data = 3;
 new_node->next = NULL;  /* obviously I cannot do that it was just to make an example of
                            what I would like to do */
  return 0;
}

你的结构中必须有一个指针来保存下一个节点的地址。您不能将其存储在结构之外的 main 中。