What is the purpose of the first “node” in the declaration: “typedef struct node { - - - } Node;”?

前端 未结 6 1303
醉话见心
醉话见心 2020-12-30 08:06

I am studying code examples from my professor in order to become better acquainted with linked data structures.

In our linked-list.c example the professor defines a

6条回答
  •  醉梦人生
    2020-12-30 08:50

    Here struct node is a type like int

    and Hence

    struct node {
      int data;
      struct node *next;
    }NodeVar;
    

    means you are declaring a single variable Node of struct node.

    like int intVar;

    typedef is to make your code understandable.

    so that when you use

    typedef struct node Node;
    

    you can use the same declaration as

    Node NodeVar;
    

提交回复
热议问题