Home > Mobile >  typedef variable to pointer variable
typedef variable to pointer variable

Time:03-13

Why list node is pointer type what's difference will be without pointer?

typedef struct node {
    char data;
    struct node *nextptr;
} node_t;
    
typedef node_t *listnode;

CodePudding user response:

it is pointer type because you have n elements, and for every element you now it data, and pointer for next element. n you may not know, so you use dynamic array of your structures. you can declare you your array using *. and after that you can give him memory. if you know n, it may be typedef node_t listnode[n];

CodePudding user response:

In dynamic allocation of memory, you need a pointer to store the base address of memory space allotted. Thus declaring a pointer to the structure of type node_t helps you to go with dynamic memory allocation.

  • Related