Suppose you have the following array declaration in a program.

```
int yourArray[5];
```

Further suppose that in the implementation of C++ you are using an int that requires 4 bytes.
i) When your program runs, how much memory is required for this array?
ii) Suppose further that your array starts at memory location decimal 100. What will be the address of yourArray[3]?
iii)If you wrote to the (illegal) index 7 position in yourArray to what address would this clobber?
a) i) The array takes 5 bytes, ii) yourArray[3] will be an int located at Address 103. iii) writing to yourArray[7] will clobber an int starting at location 107.

b) i) The array takes 10 bytes, ii) yourArray[3] will be an int located at Address 106. iii) writing to yourArray[7] will clobber an int starting at location 114
c) i) The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128
d) The purpose of a high level language is to insulate the programmer from these details. It isn’t possible to know this without probing the source to the operating system and the compiler, or extensive debugging.


c) i) The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128

a) would be correct for a 1 byte int, b) would be correct for a 2 byte int
(older MS DOS and MS Windows systems.) d) is an answer appropriate to a language
that does not provide low level access (e.g. Java.)

Computer Science & Information Technology

You might also like to view...

A plug-in is a software application that can provide additional multimedia capabilities

Indicate whether the statement is true or false

Computer Science & Information Technology

The goal of the ____ memory allocation algorithm is to find the smallest memory block into which a job will fit.

A. smallest-fit B. first-fit C. dynamic-fit D. best-fit

Computer Science & Information Technology

Use the ____ command to import a text file into MySQL.

A. IMPORT FILE B. IMPORT DATA FILE C. LOAD DATA INFILE D. LOAD TEXT FILE

Computer Science & Information Technology

Top-down program design is used to identify the program's processing steps after the outputs and inputs have been determined.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology