The malloc function in C asks the system for a block of memory of a given size. If the system has enough memory, malloc returns a pointer to that memory. If not, it returns NULL. It is important to check if the pointer is NULL before using it to avoid errors. After using the allocated memory, you must call free to give the memory back to the system. Using the pointer after freeing it is unsafe because it points to memory that is no longer yours. This example shows allocating memory for an int, storing 10 in it, and then freeing it properly.