0

I came across a stack tutorial in the C language and I can't seem to understand what the *Stack pointer is pointing towards nor the *next pointer. I would just like to have a quick explanation on what these two pointers actually point to.

typedef struct StackElement { int value; struct StackElement *next; }StackElement, *Stack; 
1
  • in general, it is a poor programming practice to hide a pointer in a typedef. I.E. the *stack will create problems with humans reading the code.\ Commented Nov 15, 2019 at 15:37

1 Answer 1

1

Neither points to anything in the example you've given. This code is just the declaration of the structure type itself. You could break the typedefs out into maybe simpler form:

struct StackElement { int value; struct StackElement *next; }; typedef struct StackElement StackElement; typedef struct StackElement *Stack; 

That is, there is a declaration of the structure itself, which contains a field next to be used by the implementation code of this stack. That field, when filled in, will point to another struct StackElement structure.

The typedef parts just make convenience names - StackElement can be used in place of struct StackElement, and Stack can be used instead of struct StackElement *.

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

1 Comment

Now I got it ! Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.