#include <stdio.h>
#include <stdlib.h>

#define NUMBER_OF_ELEMENTS 10
#define NO_MEMORY -1;

//--------------------------------------------------------------------
int main()
{
  int *test_array    = NULL;
  int *another_array = NULL;
  
  // requesting dynamic allocation of memory for the array
  test_array = malloc(NUMBER_OF_ELEMENTS * sizeof(int));

  // enough memory?
  if(test_array == NULL)
    return NO_MEMORY;
  
  //-------------------

  // requesting dynamic allocation of memory for the array
  another_array = malloc(NUMBER_OF_ELEMENTS * sizeof(int));

  // enough memory?
  if(another_array == NULL)
  {
    free(test_array);
    return NO_MEMORY;
  }
  
  // not allowed writing
  test_array[NUMBER_OF_ELEMENTS + 5] = 42;
  
  // free array
  free(test_array);
  test_array = NULL;
  
  // not freed array
  // free(another_array);
  another_array = NULL;
  
  return 0;
}

