Accessing an Array

Learn how to access and update the elements stored in an array.

Array traversal #

We can access the elements stored in an array by writing the array name, which is followed by its index in the square brackets.

The first element of an array is stored at index 0, and the last element is stored at index size-1. Array[0] refers to the first element in an array. Array[1] refers to the second element, and so on.

Example program

Suppose there are 5 elements in an array. The index value of this array will ...