What is an Array?

An array is a collection of items of same data type stored at memory location. Reason behind this is to store the data of same type. We write it as: using data type array_name[]={value}.

We can put the value of data in square bracket with array_name and can store only hat much data in curly brackets. If we give data type integer can all values will be of data type integer. The index number starts from 0. Suppose if we write size 3 then index number for first value is 0. So, total 4 values will be stored.

For Example: int arr={22,23,24,25}. // for integer

For Example: float arr1={2.3,1.4,5.6,3.8,5.9}

There are two types:

1. One dimensional array
2. Multi-dimensional array

One-dimensional array: In this type, there is only one dimension. That can be either column or row.

For Example: int A={0,1,2,3}; // one dimension

Multi-dimensional array: In this type, there are multi-dimension. Example of multi-dimensions are 2D, 3D, 4D ,etc. In this type, there are rows as well as columns. We can solve matrices. In this, when writing size, the size of row is written first then size of column.

For Example: int B; // 2D array where  is size of row and  is size of column

For Example: int C={{2,3},{3,4}},{{5,6},{7,8}}; // three dimension

Example using one dimensioal array:

int main()

{ int arr;

arr=10; arr=20; arr=30; arr=40; arr=50;

for(int i=0;i<=5;i++)

{

printf(arr[i]);

}

output: 10 20 30 40 50

Use of array in real life:

• For post office boxes;
• book pages;
• egg cartons;
• chess or checkerboard.
• use to implement mathematical vectors and matrices 