Array Storage Structure
Array Storage Structure
A[I]=BA+(I-L)*Size
Where,
I is Index to be calculated
BA is Base Address of Array
L is Lower Bound of Array
Size is size of one element of array
1 Calculate the address of A[6]. If given array is A[9] with
base address 1050 & array is Integer type array (int
takes 2 bytes / element). Also find total element in
array.
2 Calculate the address of A[8]. If given array is A[9] with
base address 1050 & array is float type array .
1082
3 Calculate the address of A[22]. If given array is A[55]
with base address 2020 & array is float type array.
Also find total element in array.
2108,55
4 Calculate the address of A[40]. If given array is A[100]
with base address 180 & array is int type array. (int
takes 2 bytes / element).
260
5 Calculate the address of A[75]. If given array is A[176]
with base address 201 & array is char type array.
276
6 Find base address of float type array whose 23rd
element at 2108.
2016
1
7 Calculate the address of A[15]. If given array is A[-22…
22] with base address 2002& array is char type array.
2039
8 Calculate the address of A[-3]. If given array is A[-9…7]
with base address 1002& array is float type array.
1026
9 Calculate the address of A[-20]. If given array is A[-57…
42] with base address 5000& array is int type array (int
takes 2 bytes / element).
5074
1 Calculate the address of A[0]. If given array is A[-29…29]
0 with base address 1000& array is float type array.
116
220
If A[6][3] at 234 in given float array A[9][10]. Array stored
in column major then find base address and last address of
an array.
2
90,526
102
If 45th element at 1234 in given char array A[9][9]. Array
stored in row major then find base address and last address
of an array.
Practical
1// Array size and element declared dynamically (from user) & display it
with address.
#include<stdio.h>
void main()
{
int arraysize,i,n;
printf("Enter the size of an array "); //Ask array size from customer
scanf("%d",&arraysize);
2// Array size and element declared dynamically (from user) in 2D Array
#include<stdio.h>
void main()
{
int row,column,i,j;
printf("Enter the size of Row an array "); //Ask array row from customer
scanf("%d",&row);
printf("Enter the size of Column an array "); //Ask array Column from
customer
scanf("%d",&column);
int array[row][column];
#include<stdio.h>
void main()
4
{
int i,n,lower,upper, baseaddress,index,datatypesize,ans,casevalue;
printf("Enter the lOWER BOUND of an array "); //Ask LOWER BOUND
from customer
scanf("%d",&lower);
printf("Enter the Upper BOUND of an array "); //Ask UPPER BOUND from
customer
scanf("%d",&upper);
printf("Enter the base address of an array "); //Ask BASE ADDRESS from
customer
scanf("%d",&baseaddress);
int arraysize=upper-lower;
int array[arraysize]; // Array Declare
#include<stdio.h>
void main()
{
int a[3][3],j,base,w=2,lr=0,lc=0,i,address,n=3;
5
/* base = Base address. , W = Storage Size of one element stored in the array
(in byte).
I,J = Subscript of an element whose address is to be found.
LR = Lower limit of row , LC= Lower linmit of COLUMN , n= no.of column
*/
printf("enter elements for int array [3][3] ");
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
printf("\nelements for array are:-\n");
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{ printf("%4d",a[i][j]);
} printf("\n");
}
printf("enter base address ");
scanf("%d",&base);
printf("enter index of element whose addres want to find ");
scanf("%d%d",&i,&j);
printf("Using ROW-MAJOR \n");
address=base+w*((i-lr)* n +(j-lc));
printf("address of element=%d, a[%d][%d] =%d ",a[i][j],i,j,address);
6
Example: Given an array, arr[1………10][1………15] with base value
100 and the size of each element is 1 Byte in memory. Find the
address of arr[8][6] with the help of Column-major order.
Number of Rows given in the matrix M
= Upper Bound – Lower Bound + 1
= 10 – 1 + 1 = 10
Formula: A[I][J] = B + ((I – Lr)+ (J – Lc) * M))*size
Address of A[8][6] = 100 + 1 * ((8 – 1)+(6 – 1) * 10)
= 100 + 1 * ((7)+ (5) * 10 )
= 100 + 1 * (57)
Address of A[I][J] = 157