next up previous
Next: Creation of an array Up: Unit 07 Previous: Arrays

Declaration of array variables

To use an array we first have to declare a variable that refers to the array.


Declaration of array variables

Syntax:

type[] arrayName;

where

Semantics:

Declares a variable arrayName that can refer to an array object with elements of type type.

Example:

int[] a;     // a is a variable of type reference to an array of integers

Note that, by declaring a variable of type reference to an array we have not yet constructed the array object to which the variable refers, and hence the array cannot be used yet.



next up previous
Next: Creation of an array Up: Unit 07 Previous: Arrays