In the previous lecture, you learned why we start indexing our arrays at zero. In this lecture, you'll learn several ways to determine the size of an array at runtime. I've already generated all the code we're going to use in this lecture so we're just going to talk about it. One way we can find out the size of an array that we've declared is by using standard size. You could look at this and say, Well, I know the size of the array. I can see it right here." But sometimes the places that we're using the size of the array are actually far away from the declaration of the array itself. This is a good way to determine, at runtime, when you're about to use the size of an array, what the size of the array is. We have this function called size, and we can hand it an array and it will tell us how many elements the array has. We'll look at the first line of output when we run this code. As you can see in that first line of output, it says we have three array elements, which is, of course, correct because we've declared an array of size 3. If your compiler doesn't support using size, which was added in C++ 17, there's another way to do this. The way you can do this is, 1st of all, you can use sizeof for the entire array. Notice this isn't a standard size, this is sizeof, and this will tell you how many bytes the entire array takes up in memory. You can then get the number of bytes for one element in that array and I often just do the zeroth element, assuming I have an array of at least one element. This tells us how many bytes a single element of the array takes. If we know how much space the entire array takes and how much space a single element takes, then we can calculate the number of array elements by taking the entire array size. Let's say 12 in this case because it's three integers, and dividing by the size of a single element, which is four in this case, and that will give us the number of array elements that we have. I'll run the code again. As you can see, 12 bytes for a three-element array of ints. Each element takes four bytes because it's an int, and then we divide 12 by 4 and we get 3. Those are two different ways to get the size of an array at runtime. Remember, we can't change the size of the array after we've declared it, so this score's array will always be three. Even though you might want to do it, it's also the case that the C++ standard does not let us dynamically figure out how large the array will be. In other words, we can't ask the user how many scores do you want to enter? Then declare an array of that variable size. The compiler has to be able to figure out at compile time how big the array will be. Now, there are numerous compilers that will let you actually do it, even though it's not in compliance with the standard, but I'm not going to teach you those ways because I want to only talk about C++ standard code. We can figure out the size of the array in multiple ways. Then we can read in this course, this is acting like there's an error here, but if I compile, this is up-to-date. So let me clean the solution and compile again. If I compile, you'll see that it compiles fine. You can ignore those red squigglies. There are a couple of warnings that we will come back and take a look at, but 1st, I want to talk about how we can read in this course. Our typical for loop, but instead of our hard-coded size here, and I will also say that we could have declared a constant for the size of the array and then just use this constant here. I know I hard-coded five in the examples in previous lectures and that was probably the worst of all worlds, but I wanted you to see how we can lock an array to manipulate particular elements of the array. But this is a good best practice to access the size of scores before running the for loop over the scores array. This is all code you've seen before here in the inside. This is the difference from what we did before. We can also print out the test scores using this as our upper bound. I'll run the code yet again, and I'll enter three scores, and it prints out what those scores are. I said we could talk about those warnings and I'll need to clean and build again to see them. Those warnings say, on line 28 and line 50, that we have a signed and unsigned mismatch using the less than relational operator. What that means is, we've declared our loop control variable to be an int, which is a signed integer. It can be negative, zero or positive. The size function, however, returns an unsigned integer so the warning is you're comparing a signed value i, right here, to an unsigned value, the return value from this function. We can actually use size_t, which is defined as some form of unsigned integer. We don't know whether it's unsigned int or unsigned long or unsigned long long, we can just use size_t, and size_t is an unsigned integer data type. Size_t is used a lot in the standard library for sizes of things like we see here, and counts of things. We will find ourselves, at least sometimes, using size_t as the data type for our loop control variable and our for loops when we're dealing with the sizes of things. I'm going to change both of these and I will also say that we haven't spent much time talking about the warnings. They're not errors so your code will run, but many programmers want what are called clean compiles. No warnings, no errors. Everything is as high-quality as possible. I felt compelled to get rid of those two warnings. If I build again, you'll see those warnings have gone away. I'll also demonstrate that the code still works the way it worked before. Even though this lecture was focused on figuring out how big an array is at runtime, we got to learn some other stuff about size_t as well. To recap, in this lecture, you learned a number of different ways to determine the size of an array at runtime. The standard size function became available in C++ 17. So if you're into the C++ 17 environment, you should just use standard size, but if that's not available to you, I also showed you how you can use the sizeof function to determine the size of the array. If you're working in Xcode, you need to configure your Xcode project to use C++ 17, and I've provided a reading showing you how to do that in the lecture resources for this lecture.