C language lab device management program code interpretation questions

Your Node

structure is a chained table structure that has a pointer to the next node, which is next.

p points to your newly created node, and all the data entered above is present there.

Since we are adding the newly created node to the end of the chain table. The end means that there are no nodes after it. And NULL means nothing.

So p->next(an attribute value of the node, a pointer to the next node)

has to be given the value NULL.

p->next=NULL;

r means a pointer to the last node of the chain table. In order to add our newly created node p to the chain table. We need to turn the value next to the next node of the last node r in the chain table into our newly created node p. So we have:

r->next=p;

Now that p has been added to the chain table, p is now the last node in the chain table.

And r now refers to a node in front of p. So it has to be changed to p;

i.e.: r=p;

p=(Node

*)malloc(sizeof(Node));

malloc() requests the space;

sizeof(Node) calculates the number of bytes occupied by the Node node in order for the malloc to surely allocate space

(Node

*) converts the space requested by malloc to a Node pointer type (forced conversion) so that p can access the requested space normally.

strcpy(p->data.ID,id);

strcpy(string1,string2) copies the value of string2 string into string1.

Here it is copying the string id, which we entered, into p->data.ID.