 In this video, I'm going to be going over question five from the compound data to workshop. So in this question, we're having a look at what happens when you pass arrays into functions. And I'm going to trace that using a memory diagram that I have here over on the left. So already have my data array set up. So I've already done this line here where I have a float array called data with these values. There are seven items here. So the arrays of length seven. And then here I have an integer array called info, which is equal to the return value or the output of this function when you pass in this array as its parameter. So we're going to get a return value from this function. And that's what this integer array info is going to be referencing. So first, we need to jump into the scope of this function. So we have our array data, which is being passed in as our parameter. And the formal parameter, the name of that is called R. And because this is the equivalent of saying float. That's a bit big. Again, it's the equivalent of saying float array R is equal to data, which we know is a shallow copy. We're saying that the float array R is a reference to a place in memory. And data is also a reference to a place in memory. That's just a reference there. It's not the actual array. So what's happening here is make this a little bit smaller, is we now have two references to the same place in memory. Oh, sorry. There's another reference to that array. When we are in the scope of that function, once we leave the scope of the function, we know this from when we did function scope. Any variables that are created within a scope only exist within that scope. So once we leave that function, R will disappear. But anyway, let's have a look at what this function returns. The first line here says that we have an integer array called result, which is a new integer array, so a new place in memory. And its length is R dot length. And R is pointing to the same array as data. So its length will be 7. So I've got result, which is pointing to array here, and it has seven places. And these will all be integers. Next in our function, we have a loop. And it's that loop that we've seen many times before already that we know goes through each item in an array, where i is representing the index of each item in an array. So if we started i is equal to zero, we're saying result zero is equal to, we've got an int casting here, array zero. So result zero is equal to array zero. So if we have a look at just that part, we've got result zero, which is here. We've got r zero, which is here. So we're taking that value and we're putting it into our result array. But first we need to cast it as an int. So this casting is treating that float as an integer. So it will all round down. So instead of 2.5 being copied over, we've got the value two. Next we know in our loop we've got i plus plus. So now i is equal to one. So we've got result one, which is this space here, is equal to with that int casting, array one, which is this one here. So again, the same thing we know we're going to be copying over that value. But that value, that float value will be cast down as an int. So that will be rounding down. So what we're really passing is a negative five. So we don't have to trace this loop so carefully because we know exactly what it's doing. It's the same loop we've seen many, many times now. So what we can do is just one by one going through each of the indexes in our array, copy over each value, but copy over the int value of that. So result two is equal to r two. Result three is equal to r three. Result four is equal to r four. Result five is equal to r five. And result six is equal to r six. And you can't have a negative zero, can you? So it's just zero. Okay, so that's what our memory diagram will look like. At this point in time, once we've finished this loop, so once we've exited this loop, we've got our return statement, which says return result. So it's this reference result, which is being returned back to where the function call was and the function call was here. So result is being returned here. So that is the equivalent of saying int array info is equal to result. And because both info and result are integer arrays, we know that that means a shallow copy, not a deep copy. So what's happening here is we now have a reference to that same place in memory here, but its name is info. And at this point, once we've returned, that means that we're returning back to the function call, which is set up, and that also means we're leaving the function. So any arrays variables that have been declared inside the scope of this function, we now no longer have access to. So that means that r was declared because it was a formal parameter. So we don't have that reference anymore. And we also don't have the reference to result because that was declared and created and had values assigned to it inside of the function. But that just means that we've lost the reference result. The arrays still exist. That's a different place in memory. It's just result that's disappeared. I'll remove that because that was just making a point. So once all of this code has been executed, this is what your memory diagram should look like. We have no traces of what was done in the function. All we have is two arrays, a float array called data, an integer array called info data has a bunch of float values and info has those same values but rounded down to the closest integer, rounded down to this int value here. So that is what the memory diagram for question five will look like.