vixxhesh
vixxhesh

Reputation: 1

how does this line in structure execute?

struct node
{
int data;
struct node *link;
};

this is for the linked list using the concept of pointers and structure. I want to know how and why we are making the pointer of the node structure.

Upvotes: 0

Views: 18

Answers (1)

ikegami
ikegami

Reputation: 385917

In a linked list, you have a chain of nodes point to the next.

head
+----------+       +----------+       +----------+       +----------+
|       ---------->|data:  123|   +-->|data:  456|   +-->|data:  789|
+----------+       +----------+   |   +----------+   |   +----------+
                   |link: --------+   |link: --------+   |link: NULL|
                   +----------+       +----------+       +----------+

(link is more typically called next.)

Upvotes: 1

Related Questions