What is Two-Dimensional Array in C language ?

two dimensional array in c

In this array we will talk about Two Dimensional Array (2-D Array) in C language in details in which following topics are included,

  • Two-Dimensional array in C
  • Declaration of Two-Dimensional array in C
  • Initialization of Two-Dimensional Array in C
  • Example of Two-Dimensional Array in C

Two Dimensional Arrays in C:

Two dimensional array in C has two subscript one subscript is stand for row and another is stand for column thats why two dimensional array also called an array matrix array in C.

Declaration of 2d Arrays in C:

The syntax of declaration of two dimensional array is similar to one dimensional array but here we have two subscript. 

datatype array_name [row size][column size];

So, if we want take input in two dimensional array from the user we must be use nested loop, one for row element and another for column element and we can also calculate total number of element in 2d array by multiplying number of row and number of column.

Example:-
                  int a[2][4];

The total number of element in this array = row * column

2 * 4 = 8 elements

Initialization of 2d Arrays in C:

A like the one dimensional arrays, two dimensional arrays may be initialized their declaration with the list of initial value enclosed in braces.

Example:-
                  int table[2][3]= {0,0,0,1,1,1};

Example of 2d Arrays in C:

#include<stdio.h>
int main()
{
  int i,j;
  int a[3][3];

  printf("Enter the element of matric:\n");
  for(i=0;i<3;i++)
{
    for(j=0;j<3;j++)
   {
    scanf("%d",&a[i][j]);
   }
}
  printf("Entered element are");
{
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  printf("%d",a[i][j]);
}
  printf("\n");
}
return 0;
}

_____________________________________________________________

2d array example in c
_________________________________________

Post a Comment (0)
Previous Post Next Post