/* Program to compare sizes of static arrays, VLAs, and malloced memory. */
#include <stdio.h>
#include <stdlib.h>

int
main()
{
  int length = 5;

  int staticArray[5];                  /* Compiler statically allocated array */
  int varLenArray[length];             /* Program dynamically allocates array */
                                   /* Programmer dynamically allocates memory */
  int * dynamicArray = malloc(length * sizeof(int)); 

  if (dynamicArray==NULL) {      /* Verify memory was available and allocated */
    printf("unable to allocate dynamic array. exiting.");
    return 1;
  }
  
  printf("sizeof(int) = %lu\n", sizeof(int) );
  printf("sizeof(staticArray) = %lu\n", sizeof(staticArray) );
  printf("sizeof(varLenArray) = %lu\n", sizeof(varLenArray) );
  printf("sizeof(dynamicArray) = %lu\n", sizeof(dynamicArray) );

  free(dynamicArray);                               /* Free memory allocation */
}
