Yubraj Rai - 1 month ago 11

C Question

I was wondering if

`current->link->data`

`current->data`

Also another concept what exactly the difference between

`current`

`current->link`

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`

.

Source (Stackoverflow)

Comments