//-----------------------------------------------------------------------------
// memoryErrors.c
//
// program will demonstrate the dynamic use of memory
// it shows what can happen if you do not take care
// of what you are doing
//
// group: group 1,13 study assistant AltiHar
//
// author: Altinger Harald 0630xxx
//
// last change: created all (Altinger Harald)
//-----------------------------------------------------------------------------
//

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

//----------------------------------------------------------------------------- 
/// 
/// The main program. 
///
/// generate Errors :-)
/// 
///  @return int  always zero 
// 
int main()
{
  int *memory = NULL;
  
  memory = malloc(sizeof(int));
  if(memory == NULL)
  {
  	return 1;
  }
  memory[0] = 'c';
  printf("%c\n",memory[0]);
  
  free(memory);  //will set the pointer to NULL!
  
  memory = malloc(4); //size needn't to be a function
  memory[0] = 'c';
  printf("%c\n",memory[0]);
  
  free(memory);  //only free memory behind last position
  
  return 0;
}

