heap memory and stack memory | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

heap memory and stack memory

i m not able to get functionality of these two. please explain me with an example

15th Aug 2016, 5:07 AM
Karan Luther
Karan Luther - avatar
4 Answers
+ 2
@Apoorva, stack being "fixed" is not really true. In contrast to heap you cannot allocate memory on the heap freely, i.e. as you like. Nevertheless, stack is dynamic, too. Example: recursive functions. For every call to a function, the local memory required for this function is allocated. If the depth of recursion depends on user input, the amount of memory required is not known when the program is started. Therefore, the difference between stack and heap is not "dynamic" or "fixed", it's how freely / self-determined you can allocate memory on it.
15th Aug 2016, 6:29 AM
Stefan
Stefan - avatar
0
Mar jao na
15th Aug 2016, 6:46 AM
Apoorva Singh
Apoorva Singh - avatar
0
@Apoorva: Hehe, I can't speak Hindu :-)
15th Aug 2016, 7:13 AM
Stefan
Stefan - avatar
- 1
You can allocate heap memory according to requirement by using codes when you don't know what the file size is gonna be. Stack is fixed
15th Aug 2016, 5:14 AM
Apoorva Singh
Apoorva Singh - avatar