Hello and welcome back, everybody.
In this lecture, we are going to implement the calculation of array sizes that we discussed in the
last lecture in the presentation.
So I wanted to go back to array C and where we haven't implemented the calculating of of the array bracket
size, we're now going to implement that.
So you can get rid of this warning here.
And we're going to start by getting the vector of the array brackets.
And you know what?
Let's just call the function because it's more like professional, right?
So we'll call array brackets, no vector.
So as I explained in the last presentation, the size is the data type multiplied by each index.
So we need to make a size variable and what's it going to be equal to the size of the data type?
Because that's what we're starting with.
So now we're just going to check if the index is above or equal the total number of array brackets.
Okay.
And if it is, that means they're accessing a pointer of some kind.
So, for example, if we imagine a char pointer ABC, we can do some things like return ABC zero, return
ABC one, you know what I mean?
So it's not an array.
So of course the index here is going to be above the vector count because this is not actually an array.
So for that reason, when this happens, we just return the size, which is the data type size, because
there's many times during compiling when we need to check the array brackets from a certain index and
then kind of add it to an offset of some kind.
And in cases where we are accessing characters in a char pointer, of course we need to be able to check
for that.
So that's where we handle this.
Okay.
So just under here, we're going to say vector Sapp, peak pointer array vac index because we're summing
from the index provided.
Right.
We're going to say struct node array bracket note equals vector peak pointer array VEC.
And if that is false or null, then we're going to return zero.
So if we peak here and we get a null because there's no elements, we just return zero.
So if there is an element, then we're going to say while array, bracket, node.
All right.
Bracket node equals vector peg pointer array vec.
And now we're just going to assert that the array bracket node bracket in a node.
Type is a no type number.
And this has to happen because like I said, when we are defining the actual arrays, we only work with
constant numbers, especially in the global scope here.
Right?
Because we can't have like an X, Y and then Y can be changed at runtime.
You know, that's not going to work.
Right?
So it has to be static numbers.
And if they do pass like a constant, constant in it or something here, then obviously we can if we
can calculate that at compile time, we'll convert it to an integer later on.
So now we're going to say init number equals array bracket note bracket dot inner ll num.
And that should be above this peaking to the next, obviously.
And then we're just going to we're just going to go size multiplied equals number and that's about it.
So now at the bottom here, we just return the size that we've calculated.
And that's pretty much it, guys.
So.
Yeah, we're going to test that now.
So we're going to say clear, make, clean, make.
I'm going to say JB Maine and we're going to break on
pause it at C 748.
Yours might be different.
It's just under the no peek.
We're going to say REM.
We're going to do print, asterisk, note.
Okay.
And if I look into the variable type,
I can see a size of 48 for the array brackets, which is perfect because essentially what we've done
is we've gone four multiplied by four multiplied by three, and we get 48.
So we go, Oh, I don't have Python.
Here we go.
Print the day type size, which is four, because it's an integer multiplied by four and multiplied
by three and we get 48.
So that is our array size.
So congratulations, you've now implemented array declarations.