How does memory management work in C?
It's very easy :) You manage it yourself. We don't need no stinkin' garbage collectors... You can use the standard memory allocators malloc() and free() (as is done in most apps intended for larger memory environments), or you can write your own using a big static array (this is often done in embedded environments). Or you can use one of the memory management toolkits out there that implement "colored" memory (often used by database engines and other systems that use transactions and want to dump transaction memory all at once). The ultimate point is C provides no "native" support for memory management beyond that provided by "the stack"; memory used for items created in blocks is returned to the stack once they go out of scope (which I suppose could be argued to be a rudimentary GC). Anyway, if you do more than trivial C development, you will learn about malloc and free, and you'll quickly learn that valgrind is your friend.