Consider the linear arrays AAA[5:50],BBB[-5:10] and CCC[1:8]
Updated on January 4, 2026
Consider the linear arrays: AAA[5:50], BBB[-5:10], and CCC[1:18].
(a) Find the number of elements in each array.
(b) Given Base(AAA) = 300 and w = 4 words per memory cell for AAA, find the addresses of AAA[15], AAA[35], and AAA[55].
Solution
(a) Number of Elements in Each Array
The formula to calculate the number of elements in an array is:
Length = Upper Bound - Lower Bound + 1
For AAA[5:50]:
Solution:
Lower Bound = 5, Upper Bound = 50
Length(AAA) = 50 - 5 + 1 = 46 elements
For BBB[-5:10]:
Solution:
Lower Bound = -5, Upper Bound = 10
Length(BBB) = 10 - (-5) + 1 = 10 + 5 + 1 = 16 elements
For CCC[1:18]:
Solution:
Lower Bound = 1, Upper Bound = 18
Length(CCC) = 18 - 1 + 1 = 18 elements
(b) Address Calculation for Array AAA
The formula to calculate the address of an element in a linear array is:
LOC(AAA[k]) = Base(AAA) + w × (k - Lower Bound)
Where:
Base(AAA) = 300 (address of AAA[5])
w = 4 words per memory cell
k = element index
Lower Bound = 5
For AAA[15]:
Solution:
LOC(AAA[15]) = 300 + 4 × (15 - 5)
= 300 + 4 × 10
= 300 + 40
= 340
For AAA[35]:
Solution:
LOC(AAA[35]) = 300 + 4 × (35 - 5)
= 300 + 4 × 30
= 300 + 120
= 420
For AAA[55]:
Solution:
AAA[55] is not a valid element of array AAA because 55 exceeds the upper bound of 50.
The valid index range for AAA is 5 ≤ k ≤ 50.