Arrays Multi-Dimensional by Sachin Mehta SignUp
Boloji.com
Boloji
Home Kabir Poetry Blogs BoloKids Writers Contribute Search Contact Site Map Advertise RSS Login Register
Boloji
Channels

In Focus

Analysis
Cartoons
Education
Environment
Going Inner
Opinion
Photo Essays

Columns

A Bystander's Diary
Business
My Word
PlainSpeak
Random Thoughts

Our Heritage

Architecture
Astrology
Ayurveda
Buddhism
Cinema
Culture
Dances
Festivals
Hinduism
History
People
Places
Sikhism
Spirituality
Vastu
Vithika

Society & Lifestyle

Family Matters
Health
Parenting
Perspective
Recipes
Society
Teens
Women

Creative Writings

Book Reviews
Ghalib's Corner
Humor
Individuality
Literary Shelf
Love Letters
Memoirs
Musings
Quotes
Ramblings
Stories
Travelogues
Workshop

Computing

CC++
Computing Articles
Flash
Internet Security
Java
Linux
Networking
Computing Articles Share This Page
Arrays Multi-Dimensional
by Sachin Mehta Bookmark and Share
 

We have seen the basic concept behind arrays in general and also one-dimensional arrays. Now we see the handling of more than one-dimensional arrays.

Two-Dimensional Arrays

The discussion so far has been in listing of values stored under a single name. However, sometimes it becomes to store a table of values. Now we all know that a table comprises of rows and columns. Consider the following data table

 ----------------------------------------

                 x1         x2

----------------------------------------

y1            100       200

y2             300      400

 ---------------------------------------

The above table consists of  2 rows and 2 columns. Now it is necessary to store this kind of data in programs, where the column represents variation of one quantity and corresponding to each column we have the row values varying  as above we have x1 and varying of y from y1 to y2.

C allows us to define such table of items by using two-dimensional arrays. The table discussed above can be defined in C as

array[2][2]

Here the first bracket value indicates the number of rows which is 2 in this case, and the second bracket is the column size (2 in this case).

 In general the declaration of two-dimensional arrays is as follows

 type array_name [row_size][column_size];

The type can be any data type inbuilt or user defined. C & C++ provides the easiest techniques to to declare arrays.

The representation of memory storage of two-dimensional arrays can be visualized as follows

                             column0             column1

                                [0][0]                [0][1]

                          ______________________

Row0----             |___100_____|____200 ___|    

                           

                               [1][0]            [1][1]

                        ______________________

Row1----           |____300____ |____400___|           

 

Initialization of two-dimensional arrays

Similar to the one-dimensional the two-dimensional arrays are initialized. For example

int array[2][3] = {1,2,3,4,5,6};

In the above case elements of the first row are initialized to 1,2,3 & second row elements are initialized to 4,5,6.

The initialization can be done row wise also, for the above example it is

int array[2][3] = {{1,2,3},{4,5,6}};

If the initialization has some missing values then they are automatically initialized to 0.

For example

int array[2][3] = {{3.4},{5}}

In this case the first two elements of the first  row are initialized to 3,4 ,while the first element of the second row is initialized to 5 & rest all elements are initialized to 0.

 Multi-Dimensional Arrays

 C allows arrays with more than two dimension, to the limit depending on the compiler.

 The general form of a multidimensional array is

 type array_name[s1][s2][s3]....[sm];

The total number of elements in any dimension of arrays is the product of all sizes included in the declaration. So it will be s1*s2*s3*....*sm.

For most applications, two dimension arrays suffice. Three dimension is maximum that you can expect to go in normal applications. Still higher dimension arrays are required in the field of scientific computing, weather forecasting, time-space analysis, etc.   

19-Mar-2001
More by :  Sachin Mehta
 
Views: 2736
 
Top | Computing Articles







A Bystander's Diary Analysis Architecture Astrology Ayurveda Book Reviews
Buddhism Business Cartoons CC++ Cinema Computing Articles
Culture Dances Education Environment Family Matters Festivals
Flash Ghalib's Corner Going Inner Health Hinduism History
Humor Individuality Internet Security Java Linux Literary Shelf
Love Letters Memoirs Musings My Word Networking Opinion
Parenting People Perspective Photo Essays Places PlainSpeak
Quotes Ramblings Random Thoughts Recipes Sikhism Society
Spirituality Stories Teens Travelogues Vastu Vithika
Women Workshop
RSS Feed RSS Feed Home | Privacy Policy | Disclaimer | Site Map
No part of this Internet site may be reproduced without prior written permission of the copyright holder.
Developed and Programmed by ekant solutions