Basics of 2D Array
The mathematical definition of a matrix finds applications in computing and database management, a basic starting point being the concept of arrays. A two-dimensional array can function exactly like a matrix. Two-dimensional arrays can be visualized as a table consisting of rows and columns.
- int a, declares an integer array of 3 rows and 4 columns. Index of row will start from 0 and will go up to 2.
- Similarly, index of column will start from 0 and will go up to 3.
Column 0 | Column 1 | Column 2 | Column 3 | |
row 0 | a | a | a | |
row 1 | a | a | a | |
row 2 | a | a | a |
This table shows arrangement of elements with their indices.
Initializing Two-Dimensional arrays: Two-Dimensional arrays may be initialized by providing a list of initial values.
int a = {1,2,3,4,5,6,} or int a = {{2,3,4},{4,4,5}};
Calculation of Address : An m x n matrix (a) where the row index varies from 1 to m and column index from 1 to n,aij denotes the number in the ith row and the jth column. In the computer memory, all elements are stored linearly using contiguous addresses. Therefore,in order to store a two-dimensional matrix a, two dimensional address space must be mapped to one dimensional address space.In the computer's memory matrices are stored in either Row-major order or Column-major order form.
Read more about this topic: Matrix Representation
Famous quotes containing the word array:
“Any one who knows what the worth of family affection is among the lower classes, and who has seen the array of little portraits stuck over a labourers fireplace ... will perhaps feel with me that in counteracting the tendencies, social and industrial, which every day are sapping the healthier family affections, the sixpenny photograph is doing more for the poor than all the philanthropists in the world.”
—Macmillans Magazine (London, September 1871)