Address of ridge memory linked with neighborhood variable 'a' ret

Posted 01 December 2013 - 10:22 AM


I'm sorta stuck at the moment with mine program and i'm not to certain what's wrong v it.

You are watching: Address of stack memory associated with local variable

#include int * create_and_fill_array(int n) //function come create and fille the array{ int a; //n=number int i; //to start the for role for (i=0; iThis article has been edited by Atli: 01 December 2013 - 11:52 AMReason for edit:: Thread location updated. Please use descriptive titles; titles the tell us what is gift discussed.


*

#2andrewsw


no much more Mr Potato Head
*
*

Re: resolve of ridge memory connected with regional variable 'a' ret

Posted 01 December 2013 - 10:30 AM


Are friend able to run the code?Are over there error messages?What does the do?What is it an alleged to do?etc.. If friend want assist you need to provide more information than you have currently which is, basically, just posting your code.Your title is nonsensical as well (it is not a title), but perhaps who will edit it because that you as soon as we uncover out what the inquiry is.

#3Ani101


Re: deal with of stack memory associated with local variable 'a' ret

Posted 01 December 2013 - 10:33 AM


*
andrewsw, ~ above 01 December 2013 - 10:30 AM, said:


Are girlfriend able to operation the code?Are there error messages?What does it do?What is it an alleged to do?etc.. If girlfriend want assist you have to provide much more information 보다 you have currently which is, basically, just posting your code.Your title is nonsensical also (it is no a title), yet perhaps someone will modify it because that you as soon as we find out what the question is.

Re: deal with of ridge memory connected with regional variable 'a' ret

Posted 01 December 2013 - 10:45 AM


a is a local range in the duty create_and_fill_array. Its memory is freed when the role returns so also if you acquire it come "work" the storage it uses can be corrupted.

Re: address of ridge memory associated with local variable 'a' ret

Posted 01 December 2013 - 10:57 AM


a is a local variety in the function create_and_fill_array. Its memory is freed as soon as the function returns so also if you gain it to "work" the memory it uses can be corrupted.

Re: attend to of ridge memory connected with local variable 'a' ret

Posted 01 December 2013 - 11:00 AM


I recommend you produce the variety in the phone call function, then happen the selection to the function to be filled. You more than likely should likewise be using dynamic memory (malloc/free) instead of the VLA.Jim

Re: attend to of ridge memory connected with local variable 'a' ret

Posted 01 December 2013 - 11:01 AM


Re: resolve of ridge memory linked with regional variable 'a' ret

Posted 01 December 2013 - 11:11 AM


I introduce you create the array in the calling function, then happen the range to the function to be filled. You more than likely should also be making use of dynamic storage (malloc/free) instead of the VLA.Jim
Aww this is specifically what this mainly we've been working on. I don't completely understand the concept about it though. Ns honestly don't understand it at all. I'll try to read up top top it yet i have actually 2 hours to revolve this in. Grr! many thanks though!

Re: resolve of stack memory connected with local variable 'a' ret

Posted 01 December 2013 - 11:21 AM


The ide is the you create range whose storage isn't regional to the duty (not top top the stack) but can be accessed indigenous any function (on the heap) by utilizing a reminder to that memory.

Re: attend to of ridge memory associated with neighborhood variable 'a' ret

Posted 01 December 2013 - 11:24 AM


The concept is that you create variety whose storage isn't local to the duty (not on the stack) however can be accessed indigenous any function (on the heap) by utilizing a guideline to that memory.
I'm utilizing the attach that you posted together I stated I'm not very an excellent at this entirety pointer and also dynamic allocation thing. This week has been a vast pain for me.

int * create_and_fill_array(int n) //function to create and also fille the array{ int *a = malloc(n * sizeof(int)); if (NULL == a) printf("ERROR: the end of memory\n"); return 0; int i; //to begin the for role for (i=0; i

Re: attend to of stack memory connected with local variable 'a' ret

Posted 01 December 2013 - 11:30 AM


return a;//Address of stack memory linked with local variable 'a' returned //a is a local array in the function create_and_fill_array. Its storage is freed when the function returns.No. A is now a pointer to storage on the heap the is not freed once the duty returns.

Re: attend to of stack memory linked with neighborhood variable 'a' ret

Posted 01 December 2013 - 11:35 AM


return a;//Address of ridge memory connected with regional variable 'a' returned //a is a local selection in the function create_and_fill_array. Its memory is freed once the role returns.No. A is now a tip to memory on the heap that is not freed as soon as the function returns.
So somewhere in the function I need to use the complimentary function?I'm incredibly sorry because that the consistent questions.

Re: deal with of stack memory connected with regional variable 'a' ret

Posted 01 December 2013 - 11:38 AM


Not that function. It's objective is to create the array, fill it, and also return the reminder so the it have the right to be accessed elsewhere. You just want to cost-free the memory once you're done through it.

Re: attend to of stack memory linked with local variable 'a' ret

Posted 01 December 2013 - 11:53 AM


Not that function. It's purpose is to create the array, fill it, and also return the reminder so that it can be accessed elsewhere. You only want to complimentary the memory as soon as you're done with it.

See more: Everyone Rides Auto Sales Corbin Ky Car Dealer, Everyone Rides Auto Sales


Not going to lie. I have actually no idea what to do but I will save looking in ~ this for the meantime. Http://www.cprogramm...ation/free.aspx

Re: resolve of ridge memory linked with regional variable 'a' ret

Posted 01 December 2013 - 12:50 PM


Wow the vast difference taking a breather makes.

#include #include //was mising from the assignmentint * create_and_fill_array(int n){ int i=0; int *a; a= malloc(n*sizeof(int)); because that (i=0; iThank you guys so much!