// initializing multidimensional arrays and function
#include <stdio.h>
// function prototype
void printArray(int [][3]);
int main()
{
// declare 3 array with initial values…
int array1[2][3] = {{1,2,3},{4,5,6}},
array2[2][3] = {{1,2,3},{4,5}},
array3[2][3] = {{1,2}, {4}};
printf(“Element values in array1 by row are: \n”);
// first time function call
printArray(array1);
printf(“\nElement values in array2 by row are: \n”);
// second time function call
printArray(array2);
printf(“Element values in array3 by row are:\n”);
// third time function call
printArray(array3);
printf(“\nNOTICE THE DEFAULT VALUE 0…\n”);
return 0;
}
// function definition, passing an array to function
void printArray(int a[][3])
{
int I, j;
// the outer for loop, read row by row…
for(i = 0; i <= 1; i++)
{
// the inner for loop, for every row, read column by column…
for(j=0; j<=2; j++)
{
printf(“[%d][%d] = %d “, i, j, a[i][j]);
}
printf(“\n”);
}
}
here the output:
Elements values in array1 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 5 [1][1] = 5 [1][2] = 5
Elements values in array2 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 5 [1][1] = 5 [1][2] = 5
Elements values in array1 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 0 [1][1] = 0 [1][2] = 0


Sign In
Create Account


Back to top









