Array syntax

As with most programming languages, in C++ several variables of the same type can be combined into an array. The elements of the array are accessed via an index. The type of the elements and the size of the array must be specified in the definition.

int m// Declare an array of integers with 5 elements
int myArray[5];

// Initialize an array of integers with 5 elements
int myArray[] = {1, 2, 3, 4, 5};

// Access an element in the array
int x = myArray[2]; // gets the third element (index 2)

// Change an element in the array
myArray[2] = 6; // changes the third element (index 2) to 6