Domanda di colloquio di Ocado Group

Why array elements are instant access when you know their index?

Risposta di colloquio

Anonimo

15 set 2022

Arrays get stored as contiguous memory slots. So if you have an array of int, each int is 4 bytes, and you know the starting index in memory (the array reference itself), so if you want to access an the nth item, you can just access it directly by: Array reference + (4*n) =>. which is instant access