Nested Struct - Difficulty in understanding the concept

Asked

Viewed 134 times

1

I have the following structures:

typedef struct DataNode

{

    int id;

} DataNode;


typedef struct Node

{

    DataNode data;
    struct Node *Next;

} Node;

typedef struct List 

{

    int size;
    Node *head;

} List;

I made a drawing to understand these nested structures because I’m having a little trouble understanding the concept of nested structures. The structures above is equal to the drawing below?

inserir a descrição da imagem aqui

Thank you.

  • 2

    It seems that you understood yes, the drawing is correct. I saw no doubt there. The one thing at least in the code that’s not exactly nested structures. These are structures composed of fields with their types, by chance some of these types are also structures. Nesting would occur if one structure were inside the other in a direct way in the code. But in the organization of memory becomes like his drawing.

  • As said by the user @Maniero, apparently you really understand the concept, I suggest you that every time you make a Struct draw on paper as it will connect with others, it seems silly, but for someone who is doubtful can help a lot and at the time of the test (if this is your case) decreases the chance of error, is just a silly tip even, but that can save life...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.