Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Multidimensional Arrays

Reply
Thread Tools

Multidimensional Arrays

 
 
Terry
Guest
Posts: n/a
 
      08-30-2003
Hi,

can someone plz tell me how multidimensional arrays (like a 2-D array)
are stored in memory? Are they like single dimensional arrays? Stored
sequentially in one "row", so to say?

Thanks

Terry

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      08-30-2003

Terry <(E-Mail Removed)> wrote in message
news:3f509baa$(E-Mail Removed)...
> Hi,
>
> can someone plz tell me how multidimensional arrays (like a 2-D array)
> are stored in memory?


C doesn't really have 'multidimensional' arrays. What
looks like one is really an 'array of arrays'.

Arrays (however many 'dimensions') are stored in contigous
memory locations.

> Are they like single dimensional arrays? Stored
> sequentially in one "row", so to say?


An array:

int arry[2][3];

is stored thus:

Low High
address address
[0][0], [0][1], [0][2], [1][0], [1][1], [1][2]

-Mike



 
Reply With Quote
 
 
 
 
Julian V. Noble
Guest
Posts: n/a
 
      08-30-2003
Terry wrote:
>
> Hi,
>
> can someone plz tell me how multidimensional arrays (like a 2-D array)
> are stored in memory? Are they like single dimensional arrays? Stored
> sequentially in one "row", so to say?
>
> Thanks
>
> Terry


C and most modern languages store 2D arrays "row-wise". That is, if
S is the data size in storage units, and W is the number of items in
a row, the actual address of the i,j 'th item is

A[0][0] + S*(i+W*j)

of course a real C maven would express the above differently,
probably with pointers, but you see what I mean.

Fortran, BTW, stores data column-wise. This is a problem for people
who have to link compiled Fortran library functions to C or vice
versa.



--
Julian V. Noble
Professor Emeritus of Physics
http://www.velocityreviews.com/forums/(E-Mail Removed)
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo".
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
casting pointers/arrays to multidimensional arrays Francesco C++ 2 11-06-2009 09:04 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Multidimensional arrays in Struts form? geclinke Java 1 06-18-2004 03:31 PM
Multidimensional arrays? anything else? d[ - - ]b ASP .Net 2 05-18-2004 12:17 PM
Cast to multidimensional arrays Jay Java 1 01-30-2004 04:27 PM



Advertisments