Array

 ARRAY

An array in C or C++ is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar types of elements as in the data type must be the same for all elements.

It is of two types :- 1. 1-dimensional array
                              2. 2-dimensional array

1-Dimensional array- One-Dimensional or Single-Dimensional array is considered as the ”list of variables of similar data types”, and each variable can be distinctly accessed by specifying its index in square brackets preceded by the name of that array. In C, the declaration of an array variable with the size is enough to allocate space for them in memory.First, you must declare a variable of the desired type. Second, you must allocate the memory to hold the array.
We declare this array in this way- datatype variable_name [size];
Example:- int A[10];
This means that an array named as A can store 10 integer values.

2-Dimensional array- A two-Dimensional array can be expressed as ‘array of arrays’ or ‘array of one-dimensional arrays’.A two-dimensional array is stored in the form of the row-column matrix, where the first index designates the row and second index shows the column.
This array is declared as - datatype variable_name[size1][size2];
Example:- int A[4][3];
This means that an array named as A have 4 row and 3 columns.

PROPERTIES OF ARRAY:-

1) An array is a derived data type, which is defined using basic data types like int, char, float and even structures (which is called the array of structures).

2) Array elements are stored in contiguous memory blocks/subsequent memory blocks in primary memory.

3) Array name represents its base address. The base address is the address of the first element of the array.

4) Array’s index starts with 0 and ends with N-1. Here, N stands for the number of elements. For Example, there is an integer array of 5 elements, then it’s indexing will be 0 to 4.

Post a Comment

0 Comments