简体   繁体   中英

What does Type * foo() mean/return?

I am implementing a Binary Search Tree. And it so happens one of my sources have a function written such that:

Node * BST_Insert(Node *root, int val)
{
//Body 
}

I already know that a pointer is a variable which contains the address of another variable and we can't assign a value to a pointer, but we can assign the address of another variable to the pointer.

My Question is what the pointers on this prototype do exactly?

Node * BST_Insert(Node *root,int val) 

Node is most likely a typedef of a structure representing a node in the Binary Search Tree.

Thus Node *root represents a pointer to the root of the BST, ie a handle to the tree structure.

Since insertion of a new node may change which node is the root of the tree, the function most likely returns a pointer to the new root node.

The Pointer is pointing at the address of the returned data, In this case your function returns a Node data type. For example if your function was returning an array you can declare it as Function Pointer to have access to the address of the returned array

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