Utilizor
Contact Us

C++ Arrays

Storing multiple values in a single variable.

C++ Arrays

Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

To declare an array, define the variable type, specify the name of the array followed by square brackets [] and specify the number of elements it should store:

string cars[4];

We can insert elements into it immediately:

string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};

Access the Elements of an Array

You access an array element by referring to the index number inside square brackets [].

Note: Array indexes start with 0: [0] is the first element. [1] is the second element, etc.