简体   繁体   中英

Why pointer in typedef?

Seeing this struct

typedef struct Node{
    void *data;
    int pos;
    struct Node *prev;
    struct Node *next;
}*lptr;

I wonder why the typedef of Node is *lptr and not lptr . What difference does the pointer make?

Although it is common to have two typedef s - one for the struct to avoid the tag, and one for the struct pointer to avoid the asterisk, like this

typedef struct Node{
    void *data;
    int pos;
    struct Node *prev;
    struct Node *next;
} Node;
typedef Node* lptr;

if the authors want to avoid writing an asterisk after lptr or Node , they could certainly typedef a pointer to struct Node .

The typedef is for a pointer type.

lptr is the type struct Node*

Because the definition (the typedef) is to a pointer type. Removing it makes lptr of type Node, * makes it a pointer to a 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