When should we use malloc ()?
This statement used malloc to set aside memory for an array of 10 integers. As sizes can change between computers, it’s important to use the sizeof() function to calculate the size on the current computer. free( arrayPtr ); This statement will deallocate the memory previously allocated.
When should I use free and malloc?
To allocate a memory block you use malloc() To reallocate a memory block with specific size you use realloc() To de-allocate previously allocated memory you use free()