c - What happens to pointers after function call -


What happens after you have made a function call from an indicative composition point to another indicator that memory is allocated is? I had asked a question before, which inspires me to ask this question:

For example:

  struct example {// variable and pointers strip clip * next; } * Head   

and then I have the datatype indicator of the string in the function:

  struct example * newNode = malloc (sizeof (struct example)) ;   

And in the same function, I link the first node (head) to another node (new node):

  head-> next = newNode;   

What is linking / pointing after the function is exited? I'm not sure that he understands, but when you add a new node at the end of your link list, then you have to go through the linklist in the first place where it ends (next indicator = zero).

For example:

  zero insert_at_end () {// We have an indicator CP that runs through the linked list, initially CP-> We just create a new node, // the straight example CP and NewOn get moloched here (head! = Null) {cp = head; While (CP-> Next! = NULL) {cp = cp-> next; } CP- & gt; Next = newnode; Else {// We link the head to newNode `s because we do not want to change the head for each new node. 'Head = newNode; }}   

But after each new node added at the end of the list, we exit the function, then when we enter the function again and go to the linked list, then it Where does it end? How will it know that CP- & gt; Next points?

At the end of each new node list, we exit the function, then what happens When we re-enter the function and where does it end to go through the linked list?

Your newnode added at the end of the list is a part of a list and is not local to your function. Therefore, when you enter the function again, the node added is still there.

How will it know that CP- & gt; Next points?


On dynamic allocation, allocated memory is allocated until it is clearly deleted. Therefore, the existence of your data is independent of the indicator or function.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -