The stack is the section of memory that is allocated for variables within functions.
Data is stored in stack using the Last In First Out (LIFO) method. This means that storage in the memory is allocated and de allocated at only one end of the memory called the top of the stack. Stack is a section of memory and its associated registers that is used for temporary storage of information in which the most recently stored item is the first to be retrieved.
The heap is an area of memory used for dynamic memory allocation. Blocks of memory are allocated and freed in this case in an arbitrary order. The pattern of allocation and size of blocks is not known until run time.
What we need to know here?The reference types will go the heap memoryThe value type will go the heap or stack based on where it is declared.
Example:
Class MyClass{int x;Public int mymethod(){ Int y;}}
Here, both x & y are value types but x will go to heap and y will go to stack.