What is the difference between stack and heap memory in C?
| Stack | Heap |
|---|---|
| Local variables and function calls | Memory from malloc(), calloc(), realloc() |
| Managed automatically | Managed by the programmer with free() |
| Very fast | Slower |
| Limited size (stack overflow) | Much bigger |
| Memory ends when the function ends | Lives 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. |