Two Dimensional Array in C Programming

The array which is used to represent and store data in a tabular form is called as ‘two dimensional array.’ Such type of array especially used to represent data in a matrix form.
The following syntax is used to represent two dimensional array.

Syntax:

  [row_subscript][column_subscript];

Example:

	int a[3][3];

In above example, a is an array of type integer which has storage size of 3 * 3 matrix. The total size would be 3 * 3 * 2 = 18 bytes.
It is also called as ‘multidimensional array.’

* MEMORY ALLOCATION OF TWO(2) DIMENSIONAL ARRAY:

Fig : Memory allocation for two dimensional array

Program :

/*  Program to demonstrate two dimensional array.
Creation Date : 10 Nov 2010 02:01:09 PM
Author :www.technoexam.com [Technowell, Sangli] */

#include <stdio.h>
#include <conio.h>

int main(void)
{
	int a[3][3], i, j;
	clrscr();
	printf("\n\t Enter matrix of 3*3 : ");
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
		scanf("%d",&a[i][j]);  //read 3*3 array
		}
	}
	printf("\n\t Matrix is : \n");
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
		printf("\t %d",a[i][j]);  //print 3*3 array
		}
	   printf("\n");
	}
	getch();
	return 0;
}

Output :

	Enter matrix of 3*3 : 3 4 5 6 7 2 1 2 3
	
	Matrix is :
	3	4	5
	6	7	2
	1	2	3_

Limitations of two dimensional array :

o	We cannot delete any element from an array.
o	If we dont know that how many elements have to be stored in a memory in advance, then there will be memory wastage if large array size is specified.

Leave A Comment

Your email address will not be published. Required fields are marked *