What value is in data[7]
?
103
Every slot of an array holds a value of the same type.
So, for example, you can have an array of int
,
an array of double
, and so on.
An array can hold object references. This is discussed in a later chapter.
The picture on the left shows an array of int.
Every slot contains an int
.
A slot of this array can be used anywhere a variable of type int
can
be used.
For example,
data[3] = 99 ;
works just like an assignment statement with an int
variable on the left of the
assignment operator.
After it has been executed, the array will look like
the picture on the right.
The value in slot 3 of the array has been changed.