Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LinkedList Pointer

0 views
Skip to first unread message

r.de...@gmail.com

unread,
Aug 31, 2005, 11:46:41 AM8/31/05
to
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.

Mike Wahler

unread,
Aug 31, 2005, 12:08:04 PM8/31/05
to

<r.de...@gmail.com> wrote in message
news:1125503201.9...@z14g2000cwz.googlegroups.com...

> 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


osmium

unread,
Aug 31, 2005, 12:15:19 PM8/31/05
to

jesso

unread,
Aug 31, 2005, 1:48:20 PM8/31/05
to

Flash Gordon

unread,
Aug 31, 2005, 2:17:42 PM8/31/05
to
osmium wrote:

<snip>

It is more likely to *confuse* people who are trying to learn C seing as
it is C++. I stopped reading when I saw the first block of code provided
is not valid C.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.

0 new messages