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