C++ Arrays

In C++, arrays allow multiple values to be stored within a single variable, making data management more efficient.

Tutorials dojo strip

Declaring an Array

To define an array, specify the data type, followed by the name and size in square brackets:

C++

This declares an array named bikeBrands that can hold four elements.

To assign values at declaration, use curly braces {} with a comma-separated list:

C++

Similarly, an integer array can store numerical values:

C++

Accessing Elements in an Array

Each array element has an index, starting at 0. Access elements by using square brackets:

C++

Output:

C++

Note: Indexing starts at 0, meaning [0] refers to the first element, [1] to the second, and so on.

Modifying an Array Element

Once an array is initialized, individual elements can be updated by referencing their index.

Example: Changing an Array Value

C++

Output:

C++

Tutorials dojo strip