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) is correct.
Explanation 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.)
You might also like to view...
Write out an adjacency matrix for this graph.
Consider the following undirected graph. vertices: A, B, C, D, E edges: (A,B),(C,D), (B,D), (B,C), (C,E), (D,E)
A ____ procedure completes its task but does not return any data to the calling procedure.
A. Private B. Sub C. Function D. Public