Sudheergv Sudheergv - 1 month ago 5
C Question

How to understand pointer 'next' in a linked list structure?

struct Node
{
int a;
struct Node *next;
};


How will
next
address point dynamically? I read
malloc
returns address value — is that right?
Please explain
struct Node *next
. Is this the default way of declaring a pointer in a struct?

Answer

Yes your declaration is correct. To understand it, see it this way. When the compiler wants to know what kind of pointer it should compile the strcut's next field. The declaration type you gave is used. Since the compiler already parses the structure before coming to this line. It understands that the next pointer type is also of same structure type. I hope this helps in your understanding.