C stack/heap

From wikinotes
Revision as of 09:09, 22 February 2019 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • 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.