Answer»
- The C programming language manages memory statically, automatically, or dynamically.
- Static-duration variables are allocated in main memory, usually ALONG with the executable CODE of the program, and persist for the lifetime of the program
- Automatic-duration variables are allocated on the stack and come and go as functions are called and return.
- For static-duration and automatic-duration variables, the SIZE of the allocation is required to be compile-time constant.
- Dynamic memory allocation in which memory is more explicitly (but more FLEXIBLY) managed, typically, by allocating it from the heap, an area of memory structured for this purpose.
- In C, the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes.
|