[MUSIC]. We've seen multi-dimensional and multi-level arrays. now let's take a look at how we represent some other structures besides just plain integers or pointers, in memory. In C, we have the concept of a struct. a struct is a definition of a composite data type that has sub-elements that are, are in turn other data types themselves. In this case, we have a small struct here with three elements inside of it. One is an integer. One is an array of integers, in this case a three element array. And the other is a pointer to an integer. So those are three parts to that struct. In memory, is going to be laid out as a continuous set of bytes for each of those parts. The first four bytes will of course be the integer i. the next 12 bytes will be the three integers of the array a, contiuously allocated. And then finally, the last 4 bytes will be a pointer to an integer in a 32 bit architecture. So, total for this struct is a 20 bite chunk of memory, continuously allocated and we can refer to the members of this structure, by the names we've given them. but the members can be of different types, they don't have to be the same. in this case these are either integers or pointers intergers, but those are very different data types. OK. So how do we access, a structure member? well, given, an instance of a struct, we can use the dot operator, just like in Java. So for example, if we declare one of these str, rec structs that we just defined, declared here, we can give it the name r1. Then we can refer to that first integer in r1 by writing r1 dot i, and that refers to just that first Integer, that is part of that larger struct, that has a couple of other things in it. OK, if we have a pointer to a struct, rather than the struct itself, in other words, we've declared not the struct r1, as we did in this case, but in pointer r to a struct of type rec. in other words, we, that would be something like the address of the r1 struct we declared previously. we're now using, we're going to be using the star and dot operators, because we first need to de-reference the struct pointer. get to the starting location of that of that struct in memory, and then offsetting that by the position of the member within the struct. OK? So this happens so often in C that we actually give it a shorthand. we give it the shorthand r right arrow i. and the arrow is drawn as a - followed by a > sign. and that's just a shorthand for doing that de-reference first, that's what the parentheses indicate, and then the dot. OK? So you'll often see this kind of construct in C because we have pointers to structs rather than the structs themselves. So, here you see a simple function that is used to set the value of that first element of this type of struct. So it takes a pointer to that struct as an argument, and a value to put in that first member. And it says, well, I have that pointer, let's de-reference it, and offset to i, that first member of the struct, and then give it the value of val. The way that ends up looking in assembly code, is very straight forward actually. Because we have the value val in eax, and we're going to have the pointer to the element in edx, and we're just going to say move that value val to edx at that address. So the parentheses, again, are the de-reference operator. In this case, we don't have an offset, because that was the, i is the very first element of the struct. So it's at that starting address. If if we had to provide an offset, there would have been an additional offset here, in front of the parentheses. OK. So let's take a look at a slightly more complex case. generating a pointer to one of those elements of that array inside of the struct. so in this case what we would like to do is find the particular element that we're interested in, by providing an index. So we're going to provide a pointer to the struct, and then an index into the array. And in this case, what we want to return is a pointer to that integer element. OK? So to return the pointer what we will do is first do that r Arrow a. that gets us to the starting address of the array within memory within that struct. And then, index that array with the appropriate offset, and then the ampersand says well I don't want the value there, I want the address of that value, and return that. Mm-kay. How we see that in assembly code, is just two simple instructions. the very first instruction computes the offset into the struct. So in this case, the offset is is four times the index to get to the right position within the array. you'll then notice we'll take that value, which we store in eax, here and add another 4 offset to it, because that array starts at four bytes into the struct. then, of course, eax has the offset within the array. And the edx is the starting address of the struct, that first parameter. We add all of those together, so we start from r, add on the 4 to get to the a portion of the struct, the array portion of the struct. And then we add on the, 4 times the index to get to the right element inside the array. And since we're returning just the address, we can stop there after we've computed the address, we don't need to actually do a memory reference.