C pointer--pull back data with a level two pointer

Source: Internet
Author: User

Now there is the need to create a binary tree root node pointer in the main function, in the Tree_create function, malloc or new binary tree node, and then in the main function can be normal access to the new node.

Note: The return value of tree_create here is void, which means that a pointer to a node cannot be returned by the return value of the function.

The way to think about this is to pull back the data from the node by a level two pointer. The specific implementation process is this:

void Tree_create (tree **tmp); int main (void) {Tree *t = null;//t is a pointer to a two-fork tree node//The address of T is passed to Tree_create function tmp// The value passed is placed in the corresponding memory unit of TMP tree_create (&t);}

Here's a bad way to analyze how their memory is stored:

void Tree_create (tree *tmp); int main (void) {Tree *t = null;//t is a pointer to a two-fork tree node//the contents of T, that is, the data in the memory unit corresponding to t//This data is either the memory address of a node, Either the null//passes this value to the Tmptree_create (T) of the Tree_create function;}

First look at the way the memory is arranged in the wrong way:

Then look at the correct way of arranging the memory:

In the way of memory display, this paper analyzes the working mode of the two-level pointer pull-back data. It also shows the wrong way.

C pointer--pull back data with a level two pointer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.