Next: , Previous: Array Declarations, Up: Arrays


4.5 References

Referencing arrays can be a little tricky. One may reference dense subsets of either sparse or dense arrays by specifying the precise range of each dimension. An error occurs if not every instance referenced has been instantiated.

For example, given the declaration int z[100], the reference z[0..9] would refer to the 1-D array of length 10 containing z[0] through z[9]. z[0..0] refers to the 1-D array of length 1 containing z[0], which is not size-equivalent to z[0], a 0-D (single instance) reference to z[0], because the number of dimensions do not match.

Indexing an array with a single pint results in a size-type of one less dimension, in other words, every dimension singly indexed is collapsed. Dimensions indexed with an explicit range are preserved. Consider the following examples, given that y is a 2-D array: