Sunday, October 11, 2009

Two – Dimensional Arrays

A two - dimensional M x N array A[M][N] is a collection or list of M x N data elements such that each element is specified by a pair of integers (such as J, K), called subscripts, with the property that

LB of Row Index £ J £ UB of Row Index

and LB of Column Index £ K £ UB of Column Index

In C/C++, lower bounds, LB, are zero. The element of A with first subscript J and second subscript K will be denoted by A [J][K].

Two–dimensional arrays are analogous to matrices in mathematics and tables in business. In it, data can be logically viewed as a table with columns & rows.

2–dimensional array can be declared as A[ 4] [5] in C/C++.

Like 1–dimensional array, 2–dimensional array is a linear and structured data type made up of a finite, fixed–size collection of ordered homogenous elements. Its accessing mechanism is direct access.

All characteristics of 1–dimensional array, like upper bound (UB), lower bound (LB), base address, and size (W) applies as well to 2–dimensional (or multidimensional) array.

Number of elements of 2–dim array =

(UB of row index – LB of row index + 1) x (UB of column index LB of column index + 1)

In case of an array A[4] 5]

no. of elements = 4 x 5 = 20 (rows) x (column)

no. of bytes = no. of elements x bytes per element

= 20 x 2 bytes per data element = 40, if each element uses two memory bytes.

No comments:

Post a Comment