Arrays are used clubbing the multiple entities of similar type. These entities can be integer, float, char, etc. In Array the memory allocation is contiguous or sequential manner.

They are manly Three type of Array:

  • Single Dimensional Array
  • Double Dimensional Array
  • Multi Dimensional Array

Single Dimensional array

Single dimension array contains only one row and all elements are arranged in sequential way.

Example :

01234
Single dimensional array

When we declare and declare an array, in memory a contiguous block can be allocated to your array of size. As we know we declare an array of integer type so each block size will be 4 byte. If it is char Array[5]  then each block are of 1 byte as character size is 1 byte.

Indexing of an array by default can be start from 0.

Declaration of Single Dimensional Array:

int array[5] = {1, 2, 3, 4, 5};

12345

int array[5] = {1, 2};

12000

Double Dimensional array

Double Dimensional array which contains rows and column. Double Dimensional are store homogenous data. When we create 2D array memory are also initialize in sequential way.

Example :

000102
101112
202122
Double Dimensional array

Double Dimensional array are similar to single dimensional array. the memory in Double Dimensional array are also allocated in sequential way. But the difference between single dimensional array and double dimensional array is Double dimensional array store data in Row and columns.

Declaration of Double Dimensional Array:

int array[3][3] ={{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

123
456
789

Multi Dimensional Array

Multi Dimensional Array are array having more then dimension such type of array are known as Multi Dimensional Array. Data in Multi Dimensional Array Sored in Row-Major order.https://en.cppreference.com/

x[0][0]x[0][1]x[0][2]
x[1][0]x[1][1]x[1][2]
x[2][0]x[2][1]x[2][2]
Multi Dimensional array

Declaration of Multi Dimensional Array:

int array[2][3][4]={{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}, {{13, 14, 15, 16}, {17, 18, 19, 20},{21, 22, 23, 24}}};

Advantages of Arrays

  • Arrays are simple data to declare and use.
  • in Arrays Data are stored in sequential way that’s why accessing element in array are easy. we can access any element array with there Index Number.
  • Searching in Array is very simple.
  • Many data structure like Linked LIst, Stack, Queue, tress, etc.
  • Two Dimensional array are used to represent the matrix.

Disadvantages of Arrays

  • The number of element stored in array should be known in advance. because one we initialize array we can not change the size of array.
  • Insertion and deletion in array more complicated.
  • Allocating more memory than the requirement cause memory wastage.
Ritesh Pandey
Ritesh Pandey

Leave a Reply

Your email address will not be published. Required fields are marked *