Home > Back-end >  Questions about the secondary pointer
Questions about the secondary pointer

Time:10-24

Struct BiTree {
Char data;
BiTree * LChild;
BiTree * RChild;
};
//first order creates a binary tree traversal
Void Create_BiTree_ByPrev_2 (BiTree * * T)
{
Char ch;
The scanf (" % c ", & amp; Ch);
If (ch=='#')
{
* T=NULL;
} else {
* T=(BiTree *) malloc (sizeof (BiTree));
if(! * T)
{
The exit (OVERFLOW);
}
(* T) - & gt; data=https://bbs.csdn.net/topics/ch;
Create_BiTree_ByPrev_2 (& amp; (* T) - & gt; LChild);
Create_BiTree_ByPrev_2 (& amp; (* T) - & gt; RChild);
}
}
Question:
1. I have found that creating a function of binary tree usually use secondary pointer (above), why not use the primary pointer?
2. The secondary pointer gave me the feeling is not very intuitive, use secondary pointer what benefits?
3. The primary pointer is used to change the variable, the secondary pointer is used to change the pointer pointing to, when would usually that need to use the secondary pointer?

CodePudding user response:

Write code to define interfaces because no planning mishandled

CodePudding user response:

Pointer used to change the value in a nutshell, level, the secondary pointer is used to change list,

Defines a pointer, for example, take him to function, must be assigned before the good memory, the function can change the value of this section of memory;
His pointer to the function, can be inside the function allocates memory, or point to another place, to build a list is much more flexible,

CodePudding user response:

Why this problem is similar to swap () with a pointer, rather than variable to achieve two data exchange, is the same reason ~

CodePudding user response:

Please refer to the "pointer to a pointer
"Wish I could help you!
  • Related