Array stores multiple values.
There are couple of ways to initialize array:
In this example an array with 3 elements is created.
Size is the count of elements in array.
It's accessed via the count
function.
Output:
Array's values can be accessed via indexes starting from 0.
If we declare the following array:
It's elements are:
So if we type the following line:
It will print:
Accessing index outside of the array results in warning
and returns value of null.
Let's have an array with 4 elements. If we access the
4th or higher index null
will be returned.
Such example is:
Output:
Let's have an example in which all elements of array are printed.