0

In the code

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

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

There are some good websites around that explain linked lists, This one seemed at a cursory look to be ok cprogramming.com/tutorial/c/lesson15.html
@AngusConnell It was my understanding that the question was more about C and pointers than about linked lists. I guess we'll see what the OP does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.