Home > Mobile >  What is the usage of double pointers between two structs?
What is the usage of double pointers between two structs?

Time:09-12

I'm trying to understand something. I want a node, and I want another node that has properties of the table I'm trying to build

typedef struct Node {
    char *data;
    int moredata;
    struct Node *next 
} Node;

typedef struct Nodewrapper {
    int size;
    int elements;
    Node ** nodeptr 
} Nodewrapper;

What functionality does the nodeptr have in Nodewrapper? How can I access stuff from the Node with nodeptr? What syntax would is correct to access stuff this way?

CodePudding user response:

I can only guess but probablt size shows how many pointers are stored and elementd how large array of structs is referenced by those pointers.

Those fields should have the type size_t.

CodePudding user response:

What syntax would is correct to access stuff this way?

To access a Node from a struct NodeWrapper, the correct syntax would be to dereference nodeptr twice because it is a pointer to a pointer.

Nodewrapper some_nodewrapper = {/* whatever */};
Node some_node == **some_nodewrapper.nodeptr;
puts(some_node.data);
  • Related