Reputation: 155
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;
Upvotes: 0
Views: 116
Reputation: 225202
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 *
.
Upvotes: 1