Arrays

An array is a sequence of either built-in or user-defined type objects stored in contiguous memory locations. By writing:
int arrayOfInt[10];
one declares, and defines, an array of ten int. The elements are indexed from 0 to the length of the array – 1. In order to assign 6, to the fifth element one can type:
arrayOfInt[4] = 6;
arrayOfInt[4] can also be used in order to access the fifth element’s value:
cout << arrayOfInt[4];


Example


#include <iostream>
using namespace std;

int main()
{   
     int arrayOfInt[10];
     arrayOfInt[4] = 6;
     cout << "Fifth array element's value: " << arrayOfInt[4];
}

Output

Fifth array element's value: 6