An array is a list consisting of the same data types. The array elements are stored in contiguous locations in the memory, which makes it easy to access array elements. The following defines an integer array of three elements, and each element of this array occupies 4 bytes in the memory (because an integer is 4 bytes in length):
int nums[3] = {1, 2, 3}
The array name nums
is a pointer constant that points to the first element of the array (that is, the array name points to the base address
of the array). In a high-level language, to access the elements of the array, you use the array name along with the index
. For example, you can access the first element using nums[0]
, the second element using nums[1]
, and so on:
In assembly language, the address of any element in the array is computed using three things:
- The base address of the array
- The index of the element
- The size of each element in the array
When you use nums[0]
in a high-level language, it is translated to [nums+0...