简体   繁体   中英

next pointer element in linked list structure

In the code

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

Is next element pointer to pointer? And what does node=node->next do?

The following isn't valid C (it won't compile):

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

You probably want:

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

Is next element pointer to pointer[?]

No, (if instantiated) next is a pointer to struct link .


what does node=node->next do?

It assigns to node where node->next would point to.

In your struct, the instance field next stores a pointer to the next link.

This line

currNode = currNode->next;

...makes the pointer currNode point to the node that follows the node that currNode previously pointed to.

The operator -> is the same as dot syntax but for pointers.

However, in the code you provided node->next wouldn't do anything because you do not have a variable named "node".

Also, the definition of you struct won't compile. It should be struct link , not struct link *node .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM