Practice mode Data Structures

An array A of 2-byte elements is stored in row-major order with base address 200, and indices start at 1. What is the address of A?

Correct answer B. 218

Explanation

With 1-based indices you must subtract the lower bounds first: address = base + ((i − 1) × columns + (j − 1)) × size. That is 200 + ((3 − 1) × 4 + (2 − 1)) × 2 = 200 + 9 × 2 = 218. Forgetting to subtract the lower bounds, a frequent error, shifts the answer by one row and one element.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.