calloc
Syntax:
  #include <cstdlib>
  void* calloc( size_t num, size_t size );

The calloc() function returns a pointer to space for an array of num objects, each of size size. The newly allocated memory is initialized to zero.

calloc() returns NULL if there is an error.


free
Syntax:
  #include <cstdlib>
  void free( void* ptr );

The free() function deallocates the space pointed to by ptr, freeing it up for future use. ptr must have been used in a previous call to malloc(), calloc(), or realloc(). An example:

   typedef struct data_type {
     int age;
     char name[20];
   } data;              

   data *willy;
   willy = (data*) malloc( sizeof(*willy) );
   ...
   free( willy );               

malloc
Syntax:
  #include <cstdlib>
  void *malloc( size_t size );

The function malloc() returns a pointer to a chunk of memory of size size, or NULL if there is an error. The memory pointed to will be on the heap, not the stack, so make sure to free it when you are done with it. An example:

   typedef struct data_type {
     int age;
     char name[20];
   } data;              

   data *bob;
   bob = (data*) malloc( sizeof(data) );
   if( bob != NULL ) {
     bob->age = 22;
     strcpy( bob->name, "Robert" );
     printf( "%s is %d years old\n", bob->name, bob->age );
   }
   free( bob );         

realloc
Syntax:
  #include <cstdlib>
  void *realloc( void *ptr, size_t size );

The realloc() function changes the size of the object pointed to by ptr to the given size. size can be any size, larger or smaller than the original. The return value is a pointer to the new space, or NULL if there is an error.