In computer science, an array data structure or simply an array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored so that the position of each element can be computed from its index tuple by a mathematical formula.

For example, an array of 10 integer variables, with indices 0 through 9, may be stored as 10 words at memory addresses 2000, 2004, 2008, … 2036, so that the element with index i has the address 2000 + 4 × i.

###

###

###

In column-major order, the elements in each column are consecutive in memory and all of the elements of a columns have a lower address than any of the elements of a consecutive column:

###

###

For example, an array of 10 integer variables, with indices 0 through 9, may be stored as 10 words at memory addresses 2000, 2004, 2008, … 2036, so that the element with index i has the address 2000 + 4 × i.

###
__One-dimensional arrays__

A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index.

As an example consider the C declaration

`int anArrayName[10];`

Syntax :

**datatype****anArrayname[sizeofArray]**;
For Example,

**int Arr[25]; will make an array of type 'int', name 'Arr' and size=25.**

###
__Multidimensional arrays__

For a two-dimensional array, the element with indices

*i*,*j*would have address*B*+*c*·*i*+*d*·*j*, where the coefficients*c*and*d*are the*row*and*column address increments*, respectively.
More generally, in a

*k*-dimensional array, the address of an element with indices*i*_{1},*i*_{2}, …,*i*_{k}is*B*+*c*_{1}·*i*_{1}+*c*_{2}·*i*_{2}+ … +*c*_{k}·*i*_{k}.

For example: int a[3][2];

This means that array a has 3 rows and 2 columns, and the array is of integer type. Here we can store 6 elements they are stored linearly but starting from first row linear then continuing with second row. The above array will be stored as a

_{11}, a_{12}, a_{13}, a_{21}, a_{22}, a_{23}.###
__Compact layouts__

Often the coefficients are chosen so that the elements occupy a contiguous area of memory. However, that is not necessary. Even if arrays are always created with contiguous elements, some array slicing operations may create non-contiguous sub-arrays from them.

There are two systematic compact layouts for a two-dimensional array. For example, consider the matrix

In the row-major order layout, the elements in each row are stored in consecutive positions and all of the elements of a row have a lower address than any of the elements of a consecutive row:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

In column-major order, the elements in each column are consecutive in memory and all of the elements of a columns have a lower address than any of the elements of a consecutive column:

1 | 4 | 7 | 2 | 5 | 8 | 3 | 6 | 9 |

For arrays with three or more indices, "row major order" puts in consecutive positions any two elements whose index tuples differ only by one in the

*last*index. "Column major order" is analogous with respect to the*first*index.###
**Here is the C Code creating a Basic Array:**

**Here is the C Code creating a Basic Array:**

/* Double-Click To Select Code */ #include<stdio.h> #include<conio.h> void main() { int arr[100],n,pos,num,i; clrscr(); printf("Enter the number of elements in the Array: "); scanf("%d",&n); printf("\nEnter %d elements:\n\n",n); for(i=0 ; i<n ; i++) { printf(" Array[%d] = ",i); scanf("%d",&arr[i]); } printf("\nArray: "); for(i = 0; i < n; i++) { printf("%5d", arr[i]); } getch(); }

###
*Output of Program:*

*Output of Program:*
Please Comment If You Liked This Post !!

This article uses material from the Wikipedia article Array data structure which is released under the Creative Commons Attribution-Share-Alike License 3.0

This article uses material from the Wikipedia article Array data structure which is released under the Creative Commons Attribution-Share-Alike License 3.0

Do you like this post? Please link back to this article by copying one of the codes below.

URL: HTML link code: Forum link code: