 Hi, everyone. Let's go over question one from the compound data one workshop. So question one asks you whether these declarations and creations of arrays are valid or not and you can see those answers there in the work solutions But what I'm going to do with these questions is to show you What that would look like in memory. So if we have a look at 1.1 We can see that it's used The first way of creating an array. It's split up the declaration and the creation in two separate lines So this first line here says I have a character array called a it exists But it hasn't created that array yet. It's just created a reference. So if I was to Draw that as a memory diagram just that first line It would look something like this So a is pointing to null Because we have a reference for a character array, but we haven't given it an array to reference. So at this point, it's null it's nothing So we can't do anything yet And we want to be really careful with nulls because we can get null pointer exceptions When we run our code and this is where a lot of bugs may come up in your assignment. So I'll show you the error you'll get here. That's question six if I were to do exactly that character Array a if I say it's equal to null and Then if I try and operate on that array or that reference to that array if I say What's the length? When I run that I'll get a null pointer exception because I've tried to operate on something That's null and you can't get the length of something. That's null so you can see there's a null pointer exception down here So we want to be really careful with that, especially when we are creating our array In those two separate steps there. So we declare it first and then we create it You want to be really mindful of that? So after that first line a is null And then we've got that second line that says a is equal to a new character array with five spaces So this key word new is telling processing. I want a new array. I want a new place in memory That is big enough for five Characters so after this line is run This will no longer point to null and it will point to an array With five places in memory big enough to fit characters and So there I've declared and I've created an array. I haven't assigned any values. Maybe I want to do that later But we don't need to worry about that. So that would be the memory diagram for 1.1 And that one is valid 1.2 we said was invalid because This is an integer not an integer array to signify that we want an array. We need to have these square brackets So 1.2 is invalid 1.3 is valid if you have a look at 1.1 and 1.3 they are very similar the only difference being There's two differences one being that one is a float array one is a character array and the other difference is That instead of declaring and creating on two separate lines. We've done it in just one line So if you know the size of your array, you know, it's going to be five then you should definitely Create and declare your array just in one line You would only use this option if you wanted to wanted to declare your array Somewhere else and you weren't sure about how big you wanted it yet. We have to be careful because Once we set our array size, that's the size So yeah, that would be the only time where you would do it separately would be if you want to declare it somewhere You're not sure what the size is yet, and you can sort that out later on most of the time You'd probably want to go for how they've done it in 1.3 1.4 is also valid because these square brackets can be before or after The array name that's fine 1.5 is invalid and that's just because of these brackets. It's the wrong kind of brackets We want the curly brackets like what we see in 1.6 So this one here if it was working correctly It would be tempting to say. Oh, well, that still wouldn't work because I've got integer values here And this is a float array, but processing will convert integers to floats If you're assigning an int to a float variable or if you're assigning Integers to a float array it will convert that for you because there's no loss of data nothing really changes I mean some things do change, but it's not too big of a change to change the number one to 1.0 So if I were to print out My second item at index one It was two, but it will convert it to 2.0 So it doesn't take much to convert that there So for 1.5 if you change the brackets that one's valid, but for now it's invalid But in saying that 1.6 is invalid Because we've got floats being assigned to an integer array so Processing will convert integers to floats, but it won't convert floats to integers That's because it doesn't want any loss of data when you convert a floating point value like 1.2 to an int you're Rounding down and you're losing that point two of a value and So processing doesn't want to lose any of that data. So this one here will be invalid You'll see you'll get an error there or firstly it gets an error because we have to Arrays of the same name, but then it will say float does not match with int okay, so Integers will convert to floats, but not vice versa if we did want to convert out Floats to integers we need to put a cast at the front So processing will only treat floating point values as integers if you tell it to by providing this cast So if that's what you wanted to do that's what would make this valid So that would work there and then lastly 1.7 that one there is valid So we can do a quick memory diagram for that one In that one there you are declaring creating and assigning all in one line So if you already know the values that you want in your array Then this is the way that you will want to create your array. So a lot easier Doesn't need a loop to allocate your values. You can just allocate it straight away or assign it straight away So if we were to do a memory diagram here We've got the reference a is pointing to a place in memory Where we've got four values one two three four And it's important to put our indexes there so our labels Up the top So that's your memory diagram there. You'll see another type of memory diagram in the compound data notes that looks a bit like This That's also valid The most important thing with memory diagrams is that you have the reference the indexes and the values as long as you have all of that Then that's good