So we're continuing with our understanding of pointers, arrays and addresses. What we're trying to show here is that while this topic is truly wonkish, in other words, it gets really into the ways of very detailed and understanding how code functions at the machine level. Namely, you have to have a really good appreciation of memory as a resource and how it's allocated and how it's addressed. One way to at least get some exposure to it, is play around with code. So I just urge you to write your own variations of what I'm doing just to make sure you get a real sense of what's going on. Here's a piece of code and it's largely to understand some of the elements of how an array is laid out, and how the machine accesses a memory cell, and use a memory cell in place of a name and also the contents of the memory cell is yet something else. So in this program, it's a modification of one we earlier used, which was to allocate some grades into an array, and then we're going to sum up and average the grades. The sum variable is going to be a double, and here's where we get into this whole notion of pointers. So here is the pointer declaration, double, asterisk. So that's essentially saying double, pointer to, sum, and that's initialized to ampersand, which is address of sum. So sum has zero stored added. This is some address that at the moment we don't know, but whatever the address is in memory, and I'm going to print that out for you. So you're going to get a sense of this magic number, because it's the compiler that gets to decide where to put things, and that's going to be different from compiler to compiler, machine to machine, and conceivably even from run to run, because on a big machine, many programs may be running, and there may be different parts of memory that get allocated to a particular program. So again, get used to, again, contextually, star here is not times, it's part of the declaration logic. It means pointer to double. Double star is pointer to double, n star is pointer to n, char star is pointer to character which frequently gives rise to the notion of a string. Here's an ordinary variable, int i, and then we do the same thing we did before, which is calculate the grades, printing them out first, and then summing them, and then printing the average. After that, we're going to look at where all of these variables are located. So I'm going to print out, sum is at, percent p is the format for a pointer address, and pointer address on a modern machine is displayed in hexadecimal, so that's not something you're used to. Hexadecimal is a base like base 10 except that its base is 16, and because we run out digits, we only have the normal 10 digits, we use the letters a, b, c, d, e, and f. F in effect is 15. But we're also going to print it as a long unsigned. So you'll see it more as an ordinary decimal number, and then we're going to print out the value that's found there. So look at what we're printing, pointer to sum. So that's the value of pointer to sum, is the address where sum itself is placed in memory, and this is the two versions of it. We get both the hexadecimal and the long unsigned, and then we do a dereferencing, star in this case means dereference this pointer to double, which means look inside it and return a double. So ampersand as an operator back up here means address, star, down here means dereference, and you dereference a pointer variable, and then you get effectively its contents. What that is going to be is whatever this sum of the grades are, and then we're going to print that stuff out, and then we're going to further print where that array starts. So it says, "grades are at", and now instead of hexadecimal, because maybe you're not used to it yet, we're going to use long unsigned, and it says grades go from long unsigned to this long unsigned. This is the base address of grades where it was stored, and this is the address of the fifth element. We'll find that it's offset by 20 because each element in grades is an integer which is stored in four contiguous bytes. Okay. So let's run that program and see that this all works. Again, I just want you to do your own experimentation. Here were my grades, here was what the program ordinarily was going to do. This is the average. Sum is at, this 0X is the format for a hexadecimal number, and then we see a seven, an f, which remember is the digit 15, fff, 5c, which is the digit, I believe 12, maybe it's c, d, e. Yeah, I think it's 12, and then b is 11, 12, 10, d is 13, 0. This translates into a long unsigned as this very big number. So like the mail box, that's the address, and stored there is the value 408. Notice 408 is the sum of 78, 67, 92, 83, 88. So indeed, that dereferencing of that pointer actually got us the same thing we would print if we had just printed sum at that point. Now look at how grades are laid out. Notice, let's forget all this beginning stuff because that's too big a number. It's located between 1920 and 1940, where sum was at 1904, and there was a variable like i. So if you think about what was being laid out in memory, there were all these individual variables. One was the variable sum, another was the pointer to sum variable, another was i, and those were all four bytes, and then you come on where the beginning of grades is. So it all makes sense if you think about where things are laid out in that program, and then it goes up to 1940 because each individual element is four bytes long, and there were five elements. So you're adding 20 and you get to the last element. Okay. Hopefully that makes sense. If that's too wonkish for you, you can probably skip this idea and still manage most of the work in the class, but if you're going to try to go on. You are going to make heavy use of C and then finally C++, then this is a subject you want to try to master, and a way to master it is to do your own experiments.