Arrays

Arrays

An array is a collection of homogenous data elements of a specific data type that have been given a single name, which is stored at contigeous memory locations.

e.g. int s[40];

int is data type, s is name of array, [40] is subscript or index.

If there is one subscript then this is one dimensional array .
if there is two subscript then this is two dimensional array e.g s[4][4].
if there is more than two then this is multi dimensional array.

1. One dimensional array

int s[5]={10,20,30,40,50};
As we know array elements are stored at contigeous memory locations, so memory map is:

2000,2002,…. are assumed as contigeous addresses where elements of an array s is store.

Program of one dimensional array:

demonstration of data entry into one dimensional array
int s[10];
for(i=0;i<10;i++) { printf("\n enter marks"); scanf("%d",&s[i]); }

Program of two dimensional array:

demonstration of data entry into two dimensional array
int s[5][6];
for(i=0;i<4;i++) { for(j=0;j<=4;j++){ printf("\n enter data"); scanf("%d",&s[i][j]); }}

Traversing or outputing an array

Demonstration ot outputing two dimensional array

printf(“entry of an array are\n”);

for(i=0;i<=4;i++) { for(j=0; j<=5; j++) printf("%d\t",a[i][j]); printf("\n"); }