home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list9_3.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  733b  |  35 lines

  1.  /* Demonstrates using pointer arithmetic to access */
  2.  /* array elements with pointer notation. */
  3.  
  4.  #include <stdio.h>
  5.  #define MAX 10
  6.  
  7.  /* Declare and initialize an integer array. */
  8.  
  9.  int i_array[MAX] = { 0,1,2,3,4,5,6,7,8,9 };
  10.  
  11.  /* Declare a pointer to int and an int variable. */
  12.  
  13.  int *i_ptr, count;
  14.  
  15.  /* Declare and initialize a float array. */
  16.  
  17.  float f_array[MAX] = { .0, .1, .2, .3, .4, .5, .6, .7, .8, .9 };
  18.  
  19.  /* Declare a pointer to float. */
  20.  
  21.  float *f_ptr;
  22.  
  23.  main()
  24.  {
  25.      /* Initialize the pointers. */
  26.  
  27.      i_ptr = i_array;
  28.      f_ptr = f_array;
  29.  
  30.      /* Print the array elements. */
  31.  
  32.      for (count = 0; count < MAX; count++)
  33.          printf("\n%d\t%f", *i_ptr++, *f_ptr++);
  34.  }
  35.