- An array is defined as a collection of variables of the same type that is referenced by a common name.
- It is a data structure which can be used to store consecutive data of the same data type.
- They can be declared for all data types in C++.
|Note: An array is a series of items that have the same characteristics under a common name|
- The computer stores arrays in a consecutive memory locations as 0, 1, 2......etc.
- It helps to access the data faster.
- Array elements are stored inside the square bracket called the subscript.
- Its memory size starts from 0, 1, 2 and so on.
Declaration of Arrays
- An array can be declared similar to the variable declaration.
- First the array type is selected, then an identifier for the array with in the square brackets.
- The number of elements should be in integer.
- For example data on the average marks over the class XI for each year can be stored in an array declared as follows.
- int students;
- This declaration will cause the compiler to allocate space for 100 consecutive integer variables in the memory.
- The number of elements in array should be fixed at compile time.