Accessing an Array

Purpose:

To store a value in a location in an array or access the value in a location in an array.

Mechanics:

<array name>[<array location>]

Example:

myArray[3] = 10; // sets the fourth position (the first position is 0) in an array to 10.

Usage:

  • The first position in an array is 0.
  • The last position in an array is <array size> - 1.

Restrictions:

  • You cannot access a position in an array above the allocated size.
  • You can only store a value in an array that is of the type of the declaration of the array.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu