C Programming Tutorial
Computer Tutorial

Two-Dimensional Arrays



Two-Dimensional Arrays

C supports multidimensional arrays. The simplest form of the multidimensional array is the two dimensional array. A two -dimensional array is, essentially, an array of one-dimensional arrays.
Syntex To declare a two-dimensional integer array of size M, N :
Variable type       name of array [Value of M][Value of N];

Sample program that stores roll number and marks obtained by a student side by side in a matrix.

# include < stdio.h >
int   main( )

int   stud[4][2]  ;
int   i, j  ;
for ( i = 0; i <= 3; i ++  )
{

printf("\n Enter roll no. and marks :") ;
scanf(" %d %d ",   &stud[i][0], &stud[i][1] ) ;

}
for ( i = 0; i <= 3; i ++  )
{

printf("\n %d %d ",   stud[i][0], stud[i][1] ) ;

}
return ( 0 );

}