Pergunta de entrevista da empresa Ocado Group

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

Resposta da entrevista

Sigiloso

15 de set. de 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