What is the difference between stack and heap memory in C?

StackHeap
Local variables and function callsMemory from malloc(), calloc(), realloc()
Managed automaticallyManaged by the programmer with free()
Very fastSlower
Limited size (stack overflow)Much bigger
Memory ends when the function endsLives until freed

See Dynamic Memory Allocation and Recursion.


Learn more about the similar topics:
Tutorials
C Pointers
C Pointer Arithmetic
C Pointer to Pointer
C Pointers and Arrays
C Pointers and Functions
C Dynamic Memory Allocation
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is a pointer in C?
What is a NULL pointer in C?
What is the difference between malloc() and calloc() in C?
What is a memory leak in C and how to avoid it?
What is a dangling pointer in C?
What is the difference between an array and a pointer in C?
What is a void pointer in C?