Yubraj Rai Yubraj Rai - 1 month ago 11
C Question

What is the difference between current->link->data and current->data in singly linked list?

I was wondering if

current->link->data
data and
current->data
provides the same result.

Also another concept what exactly the difference between
current
and
current->link
in singly linked list?

Answer

I was wondering if current->link->data data and current->data provides the same result.

May be they provide same data if same data is stored, but these are different locations i.e. if current->data is data at current node then current->link->data would be data of next node. as shown in figure.

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

Consider above typically node of singly linked list. So the member link will either point to NULL but later on it points to some other node So consider a linked list with some inserted node then

And also another concept what exactly the difference between current and current->link in singly linked list?

current is pointer to current node while current->link is pointer to next node to current node.

enter image description here

Comments