Last time we learned a number of different ways we can initialize the elements of our array. This time, we'll see why we start indexing our arrays at zero. I've done some preliminary work here to set us up for this discussion, I've declared a scores array that has these values in it, and then I'm using a for loop to print out information about the array. I'm going to print out scores I, a label that shows us which element we're looking at. I'm just going to use I, not I plus 1 because we're programmers here, so we wanted to start at zero. I'm going to print out the address of that element in the array. I use standard hex to say, I want to print out what comes next in what's called the hexadecimal or base 16. We'll see that as soon as we look at the output. I'm going to print out the address of the element in the array. Not the element in the array, not the content, I'm printing out an address here. This is the address of operator, which we've seen before. Then I'll print out the actual contents, telling it I want it back in decimal or integer form, and this will be the contents of that element. I'll label the scores, I'll print out the address of that location in memory, and then I'll print out what's contained in that location in memory. Let's go ahead and run the code. Here, we see scores zero is at this address, and this is hexadecimal, this is base 16, so each place in our address is zero through F. Zero through nine, and then A, B, C, D, E, F are the possibilities for each place in this address. The array starts at this location that ends in four. Here's the content. Then we walk down and this one's at eight, and this one's at C, and this one's at zero and four. Why are these offset by four each time? Eight plus 4 is C in hexadecimal. The reason is that we said that we want this to be an array of integers. Integers take up four bytes, so if we start the array at location, bunch of stuff four, then we need the first element of the array to have the spaces in bytes 4,5,6, and 7. Then we can put the next element of the array at eight. The four bytes we need here are 8,9, A, and B. The next element at scores 2 goes at C. That explains why the memory is laid out the way it is for this array. Arrays are always in contiguous or next to each other pieces of memory, but that doesn't explain why we start at zero. The reason we start at zero, is for efficiency. We have this base address of the array ending at four for score zero. The way we calculate the memory address for an element of the array, is we take the base address and we add the index multiplied by the size of each element in the array. If we want to access score zero, we take the base address and we add zero, the index, times 4, the size of each element in the array. We add zero. We end up with the base address, which is exactly correct. If we're trying to access the element at index 1, we take the base address and we add the index 1 times the size of the elements 4. We take four, this address that ends in four, and we add 4 to it and we get 8. Just doing one more. If we're trying to access element 2, we take the base address and we add 2 times 4, so we add 8 and 4 plus 8 in hex is C. We've accessed the element at index 2. That's why we start at zero. It's a base address plus the index times the size of each element in the array. The computer can calculate that very quickly. If we started at one, there'd have to be a subtraction every single time to say the index you're trying to access minus 1 times the element size. There's no reason to do an extra subtraction every time we access an element of an array. If we start at zero, we can avoid that subtraction and it's more efficient. To recap. In this lecture, you learned that we start indexing our arrays at zero, because the index is used to calculate an offset from the base address of the array.