Array
Learn about arrays, an essential part of your programming toolbox.
We'll cover the following...
What is an array?
In different languages, arrays are indexed differently. In some languages, array indexing starts at 1. In others, it starts at 0. In Python, array indexing starts at 0.
Arrays provide constant-time access to read and write any item in an array. This is possible because of the properties of the array. Each element of the array is of the same size. So, by taking the address of the first element, we can get the address of the element by using a calculation.
ith index element address = array first element address + size of elements * (i – first index of array)
The above calculation is just to help you understand the concept. We don’t need to perform it at runtime. We directly access the element, and the calculation happens internally.
Quiz: Understanding array address calculation
We have an array of first element addresses as 2020. The size of the element is 16, and the first index is 0. What is the address of the 6th element?
2036
2100
2084
2116
Explanation: The correct answer is . Since our array is starting from index ...