When we are done with the heap memory we've allocated, we release it with a call to free(). The free() function returns the allocated memory to the available heap pool of memory. This call does not have to occur within the same function where the memory was allocated. The prototype in stdlib.h for free() is as follows:
void free( void* ptr );
The pointer that's passed to free() must contain a value that originated from one of the calls to malloc(), calloc(), or realloc(). There is no need to cast the void* pointer argument. If ptr is NULL, free() does nothing.
We would release the memory that was allocated in the previous subsection as follows:
free( pCard1 );
free( pCard2 );
free( pHand1 );
free( pHand2 );
These four statements release each block of memory we allocated earlier. Allocated dynamic memory can be freed in any order; it does not have to be freed in the same order...