heap memory and stack memory | SoloLearn: Learn to code for FREE!


heap memory and stack memory

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

8/15/2016 5:07:08 AM

Karan Luther

4 Answers

New Answer


@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.


Mar jao na


@Apoorva: Hehe, I can't speak Hindu :-)


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