Silverfrost Logo About Us | Contact Us
Array Storage

Array Storage

There are two methods of storing arrays, row-wise and column-wise. Row-wise storage means that the elements are stored a row at a time starting from a base address and increasing towards high memory. Arrays stored column-wise have the elements stored a column at a time increasing towards high memory.

For example, consider the array consisting of 10 rows and 20 columns. The appropriate declarations in each language would be:


INTEGER*4 numbers(10,20)


INTEGER (KIND=3) numbers(10,20)


int numbers[20][10];

A row-wise array would be stored as:

numbers(0,0); numbers(1,0); numbers(2,0); ... numbers(9,0);

whilst a column-wise array would store the elements as

numbers(0,0); numbers(0,1); numbers(0,3); ... numbers(0,9);

The various language standards define Fortran as using column-wise storage, whilst C/C++ stores arrays row-wise. Therefore, a Fortran array defined as numbers(10,20), would have the equivalent C/C++ declaration numbers[20][10]. In Fortran by default the elements are actually numbered from one whilst in C/C++ they are numbered from zero.



Copyright © 1999-2017 Silverfrost Limited