Memory management in C refers to manually controlling memory allocation and deallocation.
Unlike many languages, C does not automatically manage memory for you.
There are two main types of memory in C:
malloc() allocates memory but does not initialize it.
calloc() allocates memory and initializes it to zero.
realloc() resizes previously allocated memory.
free() releases allocated memory back to the system.
Failing to free memory causes memory leaks.
You can dynamically allocate arrays using malloc or calloc.
Always check if memory allocation was successful.
A memory leak happens when allocated memory is not freed.
A dangling pointer points to memory that has already been freed.
Dynamic memory is commonly used when the size of data is not known at compile time.
Memory management is one of the most important features of C.
Be careful with these:
Dynamically allocate an array, store values, print them, and free memory.