Pointers share several characteristics with arrays, so pointers in called object location always encode
the location and the length of the contiguous objects.
At the slightest provocation, an array will decay into a pointer, so the key the array loses length
information and converts the pointer to the arrays first element.
So for example, I want to write some example here, my array here, and we will create a array and
we will put three numbers in it six, three, six and nine here.
Then we will create an integer here integer pointer key here a Peter.
All right, Raptors here.
Um, my array.
That's not my area.
So this will point to three.
And let's print it.
Here we will use the add the reference operator.
Okay.
Raptor.
And print it.
Oops.
Sorry.
Here.
We will get the pointer here as well.
But I want to print it as an array here.
And as you can see here, we got the three here and here.
So first we initialize the an integer array to the my array here with three elements, three, six and
9 to 3 elements.
So next you initialize the integer pointer here to a raptor, which the case to a pointer.
After initialization, the key raptor points to the first element of the my array here, which as you
saw here this when we print this just as an array as an variable, we got a tree the first element of
my array.
So we are now we're going to initialize an array containing colleague and we will pass the array to
function as pointer.
So firstly, let's create a struct name.
Click here.
Or we instead of calligraphy, can create them.
The car model names make model, uh, make names.
So struct car, car series, car and name will Character name.
Character name.
This is, as you know, strings is just a characters.
So that's why we're going to we used here character name 2000.
Uh, 200, uh, 56.
So it can contain 256 characters in a row.
So then we will use the creative print name function void print, name, function here car.
And car.
P.
T.
R.
Here.
Plaintiff Uh.
Se form a specified car and new line.
Then we will use a car p t r But we will use the member of operator here name.
And as you can see here, so it's actually not print name, it's just a print F here.
And then let's write our main function here.
So car, my garage here.
And we will add three car names, for example, BMW, Mercedes, Mercedes and Ford.
First year.
For.
Then we will print this print.
Name my character.
As you can see here.
The prince name function the case into a pointer.
When you call the prince name so because arrays decay into pointer, so are first element.
So my car PDR here my carburetor at points to the first car in the car names here my character.
So there's another already okay in the next lecture as well.
So you use the row operator here.
Here you use the arrow operator to access the name member of the car pointer to buy a car.
Peter.
So which itself is a character array as we declared here.
So the PRINTF format specified for SW expects SC style string, which is a character pointer and name
the case in the pointer to satisfy print F.
And now we're going to handle the decay here.
So often you pass arrays as two arguments, a pointer to the first array element and the arrays length.
So that mechanism that enables this pattern is square braces, which work with the pointers, just as
with arrays.
So now.
Uh, we will employ this technique in and edit and reprogram this code here.
So in print names, we're going to add the for loop here.
So here.
For.
Size.
I will explain all of this court later.
Don't worry.
Sighs t.
And we're going to criticize.
Still being named, uh, and we will assign it to zero.
And while e is less than, um, e is less than actual, we're going to take another parameter here.
Size t the.
And cause while he is less than in cars and cars, then increment E by one.
And here we're going to use the printer function As you as you saw earlier, we use the member of operator,
but this time we're going to use a different format here.
So this will take us here.
Shrinks, sisters, shrinks here.
We won't change that.
But we will change this here because we will pass the another argument to this format specified here.
That is the.
Car.
Peter Actually, now we're going to use the just here.
Cars.
We will we change the parameter as well.
So now we're going to use the cars e here we will pass E and then that here name.
So and also we will here, as you can see, we will we won't change this.
We have three.
This rings in my garage, which is.
BMW, Mercedes and Ford.
Then.
We will use the print names, function prints, and we will call the print names function.
And first, we're going to pass the my garage as on first parameter and next.
We will sizeof.
Here.
Size of.
Size of my garage.
Here.
Divide by size of.
Um.
Size of car.
Yeah, size of car.
As you can see here, this is a strength.
So now we can execute our function here, our code here.
And as you can see here, we got a tree of our elements, array elements here.
So now let's explain this cords by line by line.
So the print names function accepts an array in.
Two arguments here, as you can see here.
The first is.
The first is the cars.
And the second is number of elements in and car here.
So within the print names you iterate with the for loop and an index E here.
So the value of E iterates from zero here zero.
Two, um, MN colleagues, minus one.
So then you extract the corresponding cooling nine by accessing the here eight element here and then
get the name member.
Here.
The pointer plus size approach to passing arrays is ubiquitous since sister APIs, for example, in
Windows or Linux programming systems.