Array
Array
data_type array_name[Size_of_array];
string cars[4];
// Outputs Volvo
Note: Array indexes start with 0: [0] is the first element. [1]
is the second element, etc.
Change an Array Element
cars[0] = "Opel";
arr[i] = new_value;
Traverse an Array in C++
Example 3: The C++ Program to Illustrate How to Find the Size of an Arra
y
Advantages of Array
• Multidimensional Array
One dimensional Array is a group of elements having the
same data type and same name. Individual elements are
referred to using the common name and unique index of the
elements.
Score [0] Score [1] Score [2] Score [3] Score [4]
5 10 15 20 25
Score [3]=20;
Score [3]=20;
Score [4]=25;
Score [4]=25;
Other examples of One-dimensional Array
Declaration
float temperature[50];
char username[120];
double salaries[250];
Example 4
Example 5
Example 6
Activity