0
Doubt in Array's element memory allocation && Local variable memory allocation.
By seeing the first code Please say whether the arrays are using heap or stack memory for storing values? In C language ------------------------------------------------------------- By seeing the second code Please tell me,Why address of local variable 'a' is greater than address of local variable 'b' Is it due to local variables being present in stack memory? https://code.sololearn.com/cHkQXaAhf64a/?ref=app https://code.sololearn.com/c6iTv4pDAkPe/?ref=app
5 odpowiedzi
+ 1
Ans1) array being stored in continuously increasing memory location is a property of data structure itself and have nothing to do with it being in stack or heap. And till the time you don't explicitly perform dynamic memory allocation ( by using malloc() or similar functions ), your program will almost everytime put items in stack memory.
Ans 2) that depends on your language implementation and architecture.
In this case your memory stack is growing down ( towards lower memory address ) and as local variables are pushed on top of stack, "b" is being assigned a lower memory address to that of "a".
+ 3
Yogeshwaran as I said, program will always store data on stack till the time you don't explicitly tell it to store something on heap ( using malloc() ).
+ 1
Thank you Arsenic 😃👍
0
Akash Kumar Can you please explain or show, how array is using stack memory via code?
0
Thank you Arsenic .can you please tell me ,how can I find whether I storing data in stack or heap memory?
Is there any technique to identify it via code?
based on address of memory