Home > Back-end >  Create a node list function, don't take the lead as follows, if you don't return h, he ret
Create a node list function, don't take the lead as follows, if you don't return h, he ret

Time:10-07

#include
#include
Typedef struct node
{
The int data;
Struct node * next;
} Node, * LinkList;
LinkList Create_LinkListFromHead ()
{
LinkList h;
Node * L;
int n;
Printf (" set the node number ");
The scanf (" % d ", & amp; N);
L=(*) malloc (sizeof (Node));
The scanf (" % d ", & amp; L - & gt; data);
L - & gt; next=NULL;
H=L;
n--;
While (n> 0)
{
L=(*) malloc (sizeof (Node));
The scanf (" % d ", & amp; L - & gt; data);
L - & gt; Next=h;
H=L;
n--;
}
Return h;/* marked with */
}
Void PrintList (LinkList h)
{
LinkList cur;
Cur=h;
While (cur!=NULL)
{
Printf (" % d ", cur - & gt; data);
Cur=cur - & gt; next;
}
}
The main ()
{
LinkList h;
H=Create_LinkListFromHead ();
PrintList (h);
}
Label position, like going to a node, the extra node has a value of 0, why? If removed, he returned to the main function of value is what?

CodePudding user response:

Dizzy, enough malicious, return stack memory

LinkList h; The h is stack variables, namely in the stack, end of the function call, stack memory is released, so the returned h is also a pointer


CodePudding user response:

Wrong, h is a pointer, assignment for the L

CodePudding user response:

Method to generate each stack of time, will assign the return value region, the return of the return value is set in this area, so don't write return, it is likely to be spam,
https://www.cnblogs.com/youngforever/articles/3167642.html

CodePudding user response:

reference qybao reply: 3/f
method to generate each stack, will assign the return value region, the return of the return value is set in this area, so don't write return, it is likely to be spam,
https://www.cnblogs.com/youngforever/articles/3167642.html

If it is a spam, it behind him also can normal operation, the output and most of them are right, much more is in front of 0, spam words at the back of the output should be also is at sixes and sevens

CodePudding user response:

See the link of post said, the return value is the value of the eax register is uncertain, because the return value is a pointer, as long as the pointer is not illegal memory access errors occur, will be able to run, just run the wrong result,

CodePudding user response:

The first question: I think you can, I can't see how a node, at least to see the results you run

The second question:

CodePudding user response:

reference 5 floor qybao reply:
see the link of post said, the return value is the value of the eax register is uncertain, because the return value is a pointer, as long as the pointer is not illegal memory access errors occur, will be able to run, just run the wrong result,

Is look, didn't understand,,, I just started to learn, and that the results seem like the right one more zero, if it is not affirmatory, how that so similar? The 0 is how much? I'm sorry, ask more,,,

CodePudding user response:


Return h & lt;=> Mov eax, dword PTR [h]

CodePudding user response:


refer to the eighth floor response: thousand dreams life

Return h & lt;=> Mov eax, dword PTR [h]




H=Create_LinkListFromHead ();
<=>
Call Create_LinkListFromHead 062111 (dh)//call callback function
Mov dword PTR [h], eax//mov assignment

CodePudding user response:

references 9 f thousand dream life response:
Quote: refer to the eighth floor response: thousand dreams life


Return h & lt;=> Mov eax, dword PTR [h]




H=Create_LinkListFromHead ();
<=>
Call Create_LinkListFromHead 062111 (dh)//call callback function
Mov dword PTR [h], eax//mov assignment


Sorry, I am a little white, just began to learn, not so understand these,,, can you explain? thank you

CodePudding user response:

V,

Under the break with an annotation,
After running off, open the assembly page, open the register page,
Watch it return h & lt;=> Mov eax, dword PTR [h], the value of the eax

No time step through will to

Mov dword PTR [h], eax//mov assignment

The process to pay attention to the value of eax, always

You put the eax understood as a storage space, or as a variable, can also

CodePudding user response:

This is not a c, c + + standard defines behavior
Will have different results in different compilers, won't even compile
The significance of study it's not much

Tell from assembly language, the return value of a function is in the EAX register of
No significant return statements to see perform the moment, the end of the assembly code of EAX what is inside of the

CodePudding user response:



  • Related