• +91 9723535972
  • info@interviewmaterial.com

Data structure Interview Questions and Answers

Question - What is the difference between stack and heap?

Answer -

Both stack and heap are used for memory needs. The stack is primarily used to save the method execution order and local variables, and always follow the LIFO order.

Whereas heap is used for dynamic allocation and deallocation of memory blocks. It stores objects in Java. Memory allocated to the heap lives until one of the following events occurs:

  • Memory free
  • Program terminated
The size of heap memory is more when using recursion when compared with the stack, as it quickly fill-ups stack memory.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners