Professional Documents
Culture Documents
Address Calculation of Array Element - Row Major Ordering
Address Calculation of Array Element - Row Major Ordering
W denotes the size, i.e; number of bytes per data element of the
array A,
M is total numbers of rows, and
N is total number of columns in the array.
Address Calculation of Array Element - Column Major
Ordering
Address can be calculated as Column major order:-
Loc (A[I][J] ) = Base (BA) + W [M x J + I ]
Where
W denotes the size, i.e; number of bytes per data element of the
array A,
M is total numbers of rows, and
N is total number of columns in the array
Row major order
When lower bound is given.
Address can be calculated as Row major order:-
Where
BA = Base address
W = Number of bytes occupied by each element
N = Number of columns
Column major order
= BA + [n * (i - LBR) + (j - LBC)] * w
= 49 + [5 * (4 – 0) + (3 - 0)] * 4
= 49 + [23] * 4
= 49 + 92
= 141
Exercises
1. Assume that each element of an array a stored in row major order occupies
4 units of storage.
If a is declared as by each of the following and the address of the first
element of a is 100, find the address of the element array element:-
where:
type is the data type specifier of the data returned by the function.
name is the identifier by which it will be possible to call the
function.
parameters (as many as needed):
Advantages of using Functions
1. The entire program can be divided into simple subtasks and then function
subprograms can be written for each subtask.
A pointer provides a way of accessing a variable without refering to the variable name of the variable directly.
Question And Answer Session
1. When lower bound is given calculate the Row major order.
2. When lower bound is given calculate the column major order.
3. Suppose element of array A[4][5] occupies 4 bytes, and the address
of the 1st element is 49. Find the address of the element A(4,3)
when the storage is row major and the lower bound for the
compiler is zero(0).
4. List and explain the operation that can be perform on arrays.
5. What is a function?
6. Write the advantages of functions
7. What is a pointer?