Menu

Two Dimensional Arrays in C Programming

  • A Two-dimensional array is in the form of matrics, which contains rows and columns.
  • A Two-dimensional array is in the form of matrics, which contains rows and columns.
  • A 2D array a[m][n] is a table with m rows and n columns. 
  • It contains m x n elements.
  • Row index starts from 0 to m-1 and column size starts from 0 to n-1.
  • Each element has to subscripts. ie a[0][0], a[0][1],……

Syntax

       DATATYPE ARRAYNAME[ROWSIZE][COLUMN SIZE];

Example

      int m[10][10];

  • Here m is an integer array that can store 10 rows and columns.
  • It contains 100 elements.
  • location starts from m[0][0],m[0][1].........,m[9][9].

2D Array Initialization

  • int m[2][3] = {{10,15,20},{20,14,25}};
  • Total bytes = No. of rows * No. of columns * Size of datatype
  •  Total bytes  = 2*3*2 = 12

Sample Programs

  • C program to input 2 matrices and find the sum of matrices.
  • C program to input 2 matrices and find the difference of two matrices.
  • C program to input 2 matrices and find the multiplication of matrices.