Assignment 2
Assignment 2
Thus the array “cars” is used to group the cars in the parking.
NB:
Indexing of an array starts from 0. This means the first element
Is stored at the 0th index, the 2nd at the 1st ,and so on.
SOME PROPERTIES OF ARRRAYS
An array can have multiple dimensions.
Indexing of an array starts from zero.
It is a collection of data of the same data type.
We can find the size of the type of elements stored by
subtracting adjacent addresses.
QUESTION 2
To modify the example in the book, such that you rename the
variable to my mother’s name, and enter the data into the
array.
Code for an array is shown in the figure below.
The output after the code execution is shown on the figure
below
QUESTION 3
Required to use the RAM diagrams to show that program is
running or being executed in the computer. The following are RAM
diagrams to show code execution of the array.
Before the code is written the RAM diagram is as shown below
FREE
FREE
FREE
FREE
FREE
FREE
FREE
This is to show that there is no any variable declared, thus every cell of
the computer memory (RAM) is free.
After the writing the code , the computer is instructed to reserve
spaces for the array that has a finite number of variables.
Thus for our case the RAM diagram is shown as following diagram,
RESERVED
RESERVED
RESERVED
RESERVED
RESERVED
FREE
FREE
The reserved spaces are reserved for the array containing five variables.
Thus after the code execution the output can be expressed on the RAM
diagram as shown below.
Mercedes
Escalade
G Wargon
Blade
Chevrolet
FREE
FREE