0% found this document useful (0 votes)
1 views

Array Memory Representation

Uploaded by

omsingh300710
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Array Memory Representation

Uploaded by

omsingh300710
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Arrays

One-Dimensional Arrays

• A list of values with the same data


type that are stored using a single
group name (array name).
• Elements of the array are stored in
consecutive memory location.
• Only One dimension
• General array declaration statement:
data-type array-name[number-of-
items];
• Example
float arr[SIZE];
One-Dimensional Arrays
(cont.)
• Individual elements of the array can be
accessed by specifying the name of the
array and the element's index:
arr[3]
• Warning: indices assume values from 0
to number-of-items -1 !!
One-Dimensional Arrays (cont.)

The array name arr


identifies the starting
location of the array

arr[0] arr[1] arr[2] arr[3] arr[4]

element 4

Skip over 3 elements to


get the starting
location of element 4

Start
here
Some array terminology

• Size-No.of elements in an array is called


the size of the array.
• Type-The kind of values it can store.
• Array name-name of array
• Base or index address-memory location
where the first element of the array is
located.
Some Array Terminology
size
Array name

Index - also called a subscript


mark[50] - must be an int,
- or an expression that evaluates to an int

mark[5] Indexed variable - also called an


element or subscripted variable

Value of the indexed variable


mark[2] - also called an element of the array

mark[2] = 32;
Note that "element" may refer to either a single indexed
variable in the array or the value of a single indexed variable.
Memory representation

1st 2nd 3rd …… Nth


elem elem elem elem
ent ent ent ent
Array[ Array[ Array[ Array[n-
0] 1] 2] 1]
Example
Memory address
calculation
• Address of A[I]=
Base Address + size * (I - Lower Bound)
• Normally Lower Bound is 0,In some
programming language it will differ.
Memory address
calculation
Question

• Given an array int


marks[]={99,67,85,32,48,55,52};
Calculate the address of marks[4],if the
base address is 1000.
Solution

• Address of A[I]=
Base Address + size * (I - Lower Bound)
Here,
Base address=1000, I=4, Lower
Bound=0
Size of Int=2
Marks[4]=1000+ 2*(4-0) = 1008
Question

• Suppose an array A[10 … 20] is stored


in a memory whose starting address is
4000.Find the address of A[15]?
Solution

• Base address=4000
• I=15,Lower Bound=10
• Size-2
• Address of A[I]=B.A + size*(I-
Lower bound)
• Address of A[15]=4000+2*(15-10)
=4010
Thank You

You might also like