Click cells, trace nested loops line by line, and see the exam questions OCR asks. Switch between GCSE (J277, topic 2.2.3) and A Level (H446, topic 1.4.2), and between OCR's exam notation and Python.
name[row, column].[4, 5] has rows 0 to 3 and columns 0 to 4, and holds 4 × 5 = 20 elements.array cube[2, 3, 4] has 2 × 3 × 4 = 24 elements. The same ideas apply with one more index and one more loop.name[2, 3] is the fourth element of the third row, because counting starts at 0.grid[x, y] where x is the column", follow the question.Memory is one-dimensional: a numbered sequence of bytes. A 2D array is stored as one contiguous block, row after row (row-major order). The compiler turns the two indexes into one address with a formula, which is why every element can be reached in the same, constant time.
[r, c] = base + (r × columns + c) × element size. Any element is found with one calculation: direct access, O(1).[i, j, k] in an array [A, B, C] is element number (i × B + j) × C + k.Questions use the array currently shown on the Explore tab. Give an index as two numbers, for example 2,3.
array seats[4, 5] has rows 0 to 3 and columns 0 to 4. seats[4, 5] does not exist: that is an out-of-bounds error, the single most common slip.grid[x, y] with x across, follow the question.for c = 0 to 4 runs five times and includes 4. In Python range(5) runs five times and excludes 5. Writing to 5 for five columns goes out of bounds.next c comes before next r. In Python this is indentation; in OCR notation it is the order of the next lines.total = 0 before the loops. A row total must be reset to 0 inside the outer loop, once per row, not once at the start.grid[r][c]) are accepted in the exam as a 2D array. Do not mix the notations in one answer: grid[r, c] in OCR style, grid[r][c] in Python.