Question d’entretien chez Ocado Group

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

Réponse à la question d'entretien

Utilisateur anonyme

15 sept. 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