Array in c/ c++ program.

Array in c++.

    Arrays:

An array is a group of consecutive memory locations with same-named and with the same data types.
a simple variable is a single memory location with a unique name and a type. But an array is a collection of different adjacent memory locations. All these memory locations have one collective name and data type. 
The memory locations in the array are known as elements of an array.
the total number of an element in the array is called its length. 

in the above figure array member shows the data and the array indices show the index of the array.
the index of an array always and must be started from zero(0).
Arrays are used to store large amounts of similar kinds of data.

example.

If a user wants to store the marks of 50 students and declares 50 variables. it is a time-consuming process to use these variables individually. this process can be simplified by using an array. 
An array of 50 students can be declared to store these values instead of 50 individual variables.

Advantages or Uses of Array

some important advantages of an array are as follow.
  • The array can store a large number of values with a single name.
  • The values stored in an array can be sorted easily.
  • Arrays are used to process many values easily and quickly.
  • A search process can be applied to an array easily.

Declaring One-Dimensional Array

    A type of array in which all elements are arranged in the form of a list is known as one dimensional array.
it is also called a single dimensional array or a linear list. it consists of one column or one row.
the process of specifying array name, length, and data type is called array declarations.

syntax 

        The syntax of declaring a one-dimensional array is as follows.

                        Data_ Type Identifier [length];
Data_ Types indicates the data types of the values to be stored in the array.
identifier it indicates the name of the array.
the length indicates the total number of elements in the array. it must be a literal constant or symbolic constant.

example of array



in above example the array is declare of 9 element. it allocates 9 consecutive locations in memory. The index of the first element is 0 and the index of the last element is 8.