Hi, in this segment, we'll be talking about using pointers in C++, And functions. All right, so for pointers, I'm going to talk a little bit briefly about how C++ is storing the values of these numbers that we're working with, okay. I won't get into a lot of detail, but I'll draw a picture here. So for each Each number is stored in memory. All right, and there are two components, two aspects to each number. One is, The value of the number, whether it's an integer or a double, and that's as we'd expect. However, the operating system needs to know where to look to retrieve that value, when we're referring to that variable. And so we have address as well. So each variable has an address, and it has a value. Okay, and just for simplicity, I'm going to label the addresses 1, 2, 3, 4, and so on. Okay, so let's say that we have declared an integer a, And we're going to give it a value of 3. Okay, we can also declare what's called a pointer. And a pointer doesn't actually store a value, it stores an address. So here, I'm going to declare a pointer. We declare it with a *, and I'll call it b. So the value of a pointer is actually the address of another variable. Okay, so here, I might store as the value of my pointer, the address of int a, okay? So let's look at how that works in the code. So I create an integer a, and I'm also going to create a pointer b. Now b by itself at this point is uninitialized, it doesn't have a value. The way we initialize the value of a pointer is through a non-pointer element of the same type, okay. So I will say that, b is = to the address of a. So if we want to get the address of a, we actually use the ampersand. So let me write that here, so the address of a is = to this & a, okay? So I'll do that here. b is = to &a. So now, if we are to print to the screen, Actually let me give me a a value, I'll say a = to 4. Okay? Now, one other thing before I print the screen. If we want the value of a pointer, or rather the value that a pointer points to, the value pointed to, We can use the asterisk. So *b Would give you, in this case that I've showed here, 3. Okay. And so here, I've simply set b to store the address of a, and yet when I print out the value of b, It will give me the value stored at the address that it contains. So it should print out three, exactly. Now, what happens if I change the value of a? Now let's say a is now = to 4. What will that do to b? Will b still be 3, or will it now be 4? Let's look at that. You can see that the value pointed to by b has changed to 4, why? Because, b is only storing the address. And so here, when we've changed the value of 3 to 4, b is still pointing, To that address in the memory, okay. Now, while I've shown this demonstration with integers, you can actually have pointers of any other object in C++. You can have pointers of vectors, okay? So let me do that. Let's create a vector, standard vector, Of type double. And I'll create a regular vector here, vec1, and I'll create a pointer to a vector, vec2. And, let me initialize vec1 to have length 2 and values of 3.1, as an example. And in order to initialize vec2, I again as before I say, vec2 is = to the address using & of vec1, All right. Now vectors have functions, as we've talked about before. All right, we can look at the size of the function. So how does that work with a pointer to a vector? Now with a regular vector, as is the case with vec1, we would just do dot, and for example size. Right? And, As we can see here. Okay, it gave me an error, oops. This is important for you to recognize. Okay, I forgot my semicolon, and it gives a helpful hint here. It expected a semicolon before return 0, okay? So, now we should be able to run it. And again, I forgot to save it. So now we should be able to run it. Okay, so it's given us the value of 2, the size of vec1. Okay, now in order to do that same thing with the pointer, We actually don't use the dot anymore. We dereference the vector, so we instead of looking at the reference that the pointers pointing to, we look at the value and we do that through this error, this arrow, excuse me, through the arrow. And then we can use the same function name size, okay. And now as we run it, we can see it's printed the same size. We can As before, If we change something with vec1, so I'm going to resize vec1, maybe make it 3. And even though we only changed it on vec1, the same change will show up in vec2 because again, it points to that address. And I have saved my program, and so now I can run it. You can see, they were both 2, 2 in the beginning, when we resized vect1. Both vect1 and vect2 have changed to a size of 3. Okay, now I want to change gears a little bit, and talk about iterators. So with the for loop that we talked about before, we used an integer to increment from one element to another, for it to iterate the for loop. There's another way to do it, and iterators are related to pointers. And so that's why I waited to talk about it until now. In the case of a vector, There's what's called an iterator. And an iterator is simply an object that points to a single element in an array of elements or a range of elements. And it also knows where either the next element in that range is, or where the previous element in the arrange is, depending on which direction the reiterator is going, okay. And, the reason I'm bringing this up is because, we do use an iterator in the coding assignments, and I'll point that out to you, as we go over the template file. All right, and so I wanted you to understand what's going on there. So in this case, I will create a vector, and I'll iterate over this vector within a for loop, okay? So I'll create a standard vector of doubles, call it vec, And, I'll do a for loop. So, I will declare the iterator here, so it's a standard vector of doubles. It's an iterator over a standard vector of doubles, all right. And I will call it it. And the vector class has an object that is the beginning iterator and an ending iterator. And so I'll set this equal to the beginning iterator, and the function to retrieve that iterator is begin. Okay, and the conditional statement in this case wont be a less than, it'll actually be not equal to. So as long as the iterator is not equal to, so the not equal condition you'll use with the exclamation point and the equal sign. So if the iterator is not equal to vec.end, Then we'll go through the for loop into iterate. We're actually have the same syntax here, it++. Of course, in this case, it's not mathematically adding 1 to the iterator, because the iterator isn't a number. It's just iterating from the current element in this range of elements to the next element, all right. And so just to demonstrate what's going on, I'll print this screen. I'll print to the screen the values at each point, okay, Actually, I'll print to the screen, the values of sort of the index of the iterator. And so you can see this is similar to the pointer that we're using this star or the asterisk, it to sort of dereference the iterator, to get some information out of the iterator, essentially. Okay, and so now if I run that, it gives us the value of the vector at each of those points. So, we only had two components, and so it gave us the first and second components. Just to illustrate what's actually going on, I will change the value of the second component so vec[1] I'll set = to 4.3. So now as you run it, you'll see that it outputs. So it star points to the first element in the vector, and that prints out 3.1. And then on the second loop, star IT points to the second element in the vector which has a value of 4.3 Okay. So again, it's pointers and iterators aren't always the same thing, but they are related. And a pointer can be used as an iterator at times. And then iterator can act like a pointer. Okay. So, let's end this segment here, and in the next segment, we'll move on to discussing functions.