LinkedList Pointer

R

r.devaraj

consider foll. piece of code.


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

struct node *list; (say the list as 1->2->3)

printf("%d%p",list,&list);
list holds address of node 1. list->next contains address of 2.
&list tells the space allocated for list itself.

i couldn't get what is the value of &(list->next) and what it
signifies?

is it the place where address of 2 is stored??

Why it need to be stored additional to node 2 and how it is got back?

elaborate plz.


Thanks.
Deva.
 
M

Mike Wahler

consider foll. piece of code.


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

struct node *list; (say the list as 1->2->3)

printf("%d%p",list,&list);
list holds address of node 1. list->next contains address of 2.
&list tells the space allocated for list itself.

No. &list gives the address of the pointer named 'list'.
Nothing to do with allocated size(s).
i couldn't get what is the value of &(list->next) and what it
signifies?

is it the place where address of 2 is stored??

Not it's the place where the pointer 'list->next' is stored. IOW
the address of that pointer. (Pointers not only store addresses,
they occupy addresses.)
Why it need to be stored additional to node 2 and how it is got back?

elaborate plz.

I'm unsure of exactly what that last question means. The pointer 'next'
is made part of the 'struct node' so that the subsequent node can
be accessed. It's the 'link' part of 'linked list'.

-Mike
 
O

osmium

consider foll. piece of code.


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

struct node *list; (say the list as 1->2->3)

printf("%d%p",list,&list);
list holds address of node 1. list->next contains address of 2.
&list tells the space allocated for list itself.

i couldn't get what is the value of &(list->next) and what it
signifies?

is it the place where address of 2 is stored??

Why it need to be stored additional to node 2 and how it is got back?

elaborate plz.

Perhaps this will help.

http://www.inversereality.org/tutorials/c++/linkedlists.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top