Pointers share several characteristics with arrays, so pointers include object location.
Arrays encode the location and the length of the contiguous objects.
At the slightest provocation, an array will decay into a pointer, so a decayed array loses length
information and converts the pointer to the Array's first element.
So, for example, I want to write some example here.
My array here and we will create an 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.
Key.
Or Right.
Ray.
Peter here.
Um, my array.
That's the Mary.
So this will point to three the 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.
Um, here.
So first we initialize the an integer array, uh, to the my array here with three elements, three,
six and nine, the three elements.
So next you initialize the integer pointer here to array Peter, which decays to a pointer.
After initialization, the key array 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 a variable, um, we got a three 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 a pointer.
So firstly, let's create a struct named colleague here.
Or we instead of cooling, we can create the the car model names make model make names.
So struct car cars here 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 2200 uh 56.
So it can contain 256 characters in a row.
So then we will use the create a printname function void Printname function here car.
And car, Peter.
Here printf s format specifier, car and new line.
Then we will use a carpenter, but we will use the member of operator here name as you know as you can
see here.
So it's actually not print name.
It's just a printf 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 here, Mercedes and Ford.
Fourth year.
Fourth.
Then we will print this.
Print name.
My garage.
As you can see here.
The print name function decays into a pointer when you call the print name.
So because arrays decay into pointers to their first element.
So my car here, my car printer at points to the first car in the my car names here, my garage here.
So there's another array decay in the next lecture as well.
So you use the arrow operator here.
Here you use the arrow operator to access the name member of the car pointed to by a car.
Peter So which itself is a character array, as we declared here.
So the printf format specifier S expects a C style string, which is a character pointer and name decays
into pointer to satisfy printf.
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.
Or.
Size t.
I will explain all of this code later.
Don't worry.
Size T and we're going to create a size T object named A and we will assign it to zero.
And while E is less than, um, e is less than.
Actually, we're going to take the another parameter here.
Size t the.
And cars while e is less than n 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 Azure Strings, C-style strings here.
We won't change that, but we will change this here because we will pass the another argument to this
format specifier here.
That is the.
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 here.
We will pass E and then that your name?
So and also we will here.
As you can see, we won't change this.
We have three.
A strings in my garage.
Which is.
BMW, Mercedes and Ford.
Then.
We will use the print names function.
Print name.
We will call the print names function.
And first, we're going to pass the my garage as an first parameter.
And next.
We will size of.
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 strict.
So now we can execute our function here.
Our code here.
And as you can see here, we get a tree of our elements, array elements here.
So now let's explain this code by line by line.
So the print names function accepts an array in.
Two arguments here, as you can see here.
The first is.
Uh, the first is the cars.
And the second is number of elements in n cars 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.
To, um.
N colleagues.
Minus one.
So then you extract the corresponding colleague nine by accessing the, uh, here element here, and
then get the name member.
Here.
The pointer plus size approach to passing arrays is ubiquitous.
C style APIs, for example in Windows or Linux programming systems.