简体   繁体   中英

Pointer in typedef struct

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;

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 * .

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