previous | start | next

## Arrays and Pointers

- When an array is passed into a function, it is actually a pointer to the starting element of the array.

  >     double maximum(const double a[], int a_size)
  >     {
  >        if (a_size == 0) return 0;
  >        double highest = a[0];
  >        int i;
  >        for (i = 0; i < a_size; i++)
  >           if (a[i] > highest)
  >              highest = a[i];
  >        return highest;
  >     }

- The declaration gives the illusion that an entire array is passed to the function, but in fact the function receives only the starting address of the array.

  >     double maximum(const double* a, int a_size)
  >     {
  >        /* identical code as above yields same results */
  >        . . .
  >     }

- It is essential that the function also knows where the array ends.

previous | start | next