简体   繁体   中英

What exactly the meaning of structure pointer

struct Node
{
    int data;
    struct Node* left, *right;
};

What exactly the meaning of this struct Node * ? Is the function below returning a pointer to a Node?

struct Node* newNode(int data)
{
    struct Node* node = new(struct Node);
    node->data = data;
    node->left = node->right = NULL;
    return (node);
}
struct Node;

Is the name of your struct.

What exactly the meaning of this struct Node*?

struct Node* node;

You're declaring a pointer to the struct Node that needs to be allocated with some memory. There is no new keyword in C. You need to use malloc() to allocate the required bytes of memory. You can allocate that like this:

struct Node* node = (struct Node *)malloc(sizeof(struct Node));

Is it returning a pointer to a Node?

This line:

return (node);

Returns the type of struct Node* to the function.

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