Terry said:
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
(e-mail address removed)
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/
"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo".