Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
Arrays1:38 with Amit Bijlani
Learn how memory offsets are used to access arrays.
[Amit Bijlani] Let's talk about Arrays.
Now that you understand pointers a little better, it will probably be easier for you to understand Arrays.
Why? Because Arrays are essentially a kind of like pointers.
They differ a little bit but they are pointing to the very first element in the Array.
Let's look at an Array.
You have an int that stores 3 prime numbers and as you can see, when I said that, it allocated memory for 3 integers.
Now, it hasn't initialize yet because we haven't stored any data there but it knows that you want to store 3 prime numbers.
And, the way the memory offset works is that the first prime 0 is always pointing to the very first memory address.
That's why use all the index in an array starts with a 0 because you are pointing to the first memory address
and every subsequent index increments that memory address so you can point to the next value in that array.
That's why I put in the comments memory address + offset.
What's the offset? The offset is whatever you put in the box brackets.
You have prime 0. That's the very first element in the array. Primes 1 would be the 2nd element in the array.
It takes the memory address + the offset or the first memory address + the offset to go on to the next item in the array.
Hopefully, that clarifies what arrays are.
You need to sign up for Treehouse in order to download course files.Sign up