Array
Array is derived data type and it is a group of elements of same type.
Properties of Array
1. Each element of the array is same type and same size
2. Elements of the array are stored in Continuous memory
3. All the elements share the name but differentiated by means of index.
Declaration of C Array
Data type array_name [array_size];
Example
int mark[5];
Memory Allocation
Initialization of Array
int mark[5] = {19,10,8,17,9}
Printing the array elements
for(i=0;i<5;i++)
{
printf(“ %d \n”, mark[i])
}
Multidimensional Arrays
In C programming, it is possible to create an array of arrays. These arrays are known as
multidimensional arrays. For example,
int x[3[4];
Here, x is a two-dimensional (2d) array. The array can hold 12 elements. It can store
elements with 3 rows and each row has 4 columns.
Code to get input for two dimensional array
for(i =0;i<3;i++)
{
for(j=0;j<4;j++)
{
Scanf(“%d”, &x[i][j]);
}
}