Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that a C array has been declared as follows: int a[5][8][4]; (a) Give the access function for this array, assuming that the address of

Suppose that a C array has been declared as follows:

int a[5][8][4];

(a) Give the access function for this array, assuming that the address of a is 1000 and

int values occupy four bytes.

(b) What is the address of a[2][4][3]?

Here are the notes:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Implementation of Array Types The code to allow accessing of array elements must be generated at compile time. At run time, this code is executed to produce element addresses Suppose that list is a one-dimensional array whose lower subscript bound is 0. The following access function will compute the address of list [k] address (list [k]) address list [0 k element size The first operand of the addition is the constant part and the second is the vari- able part. If the element type is statically bound and the array is statically bound to storage, then the value of the constant part can be computed before mn time. However, the addition and multiplication operations must be done at run time. The access function can be generalized to allow an arbitrary lower bound address (list [k]) address (list [lower bound] (k-lower bound) element size) Next, it is rewritten so that it consists of a constant part and a variable part: address(list [k]) address(list [lower bound] lower bound element size) (k element size If the address of the anray is not known until run time, the subtraction must be done when the array is allocated. A one-dimensional array will require acompile-time descriptor. A mn-time descriptor may be also be needed if mn-time checking of index ranges is performed or if any attributes of the array are dynamic If the subscript ranges are static, the ranges can be incorporated into the code that does the checking, eliminating the need for the run-time descriptor

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions