C stack/heap

From wikinotes
  • stack: memory storing local scope variables. stack variables get destroyed when out of scope.
  • heap: your system memory (access with malloc/free)


main problems

  • if retrieve block of memory from malloc, and have pointer on stack, pointer gets lost when out of scope.
  • STACK OVERFLOW: storing too much data into the stack can cause program to crash
  • SEGMENTATION FAULT: storing a pointer on the stack, then returning/passing it to function causes crash because the pointer is removed from the stack as it leaves scope.