// pointer_arithmetic_test.c - Demonstration pointer arithmetic

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

#define NUM_ELEMENTS 5

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

  int count = NUM_ELEMENTS;
  int *help_ptr = test_array;

  // assign whatever values to the elements of the array
  while(count--)
    *help_ptr++ = count * 2;

  // now let's have a look what the array contains
  count = NUM_ELEMENTS;
  help_ptr = test_array;
  while(count--)
    printf("%d ",*help_ptr++);
  printf("\n");

  // what does element 3 of the array contain?

  printf("Element 3 contains the value %d\n",
         *(test_array + 3));
  // ok, now we don't need the array any more, let's free it
  free(test_array);
  test_array = NULL;

  return(0);
}
