Pointer arithmetic here a pointer points to memory and the type of the pointer determines the type of
the data that can be accessed through the pointer.
So here.
So, for example, an integer type pointer will point to an integer in memory, and you reference the
pointer to get the integer.
So if the pointer allows it, you can change its value through the pointer arithmetic.
So for example, you can increment or decrement the pointer.
So what happens to the value of the memory address depends on the type of pointer.
So assigns type the pointer points to a type.
Any pointer will change the pointer in units of the size of that type.
So if you increment the integer pointer, it will point to the next integer in memory and change in
the memory.
Others depends on the size of the integer.
So this is equivalent to array indexing here.
So where an expression such as for example v one means you should start at the memory location of the
first item in the V, and then move one item further in memory and return the item here.
So let's create an V variable here or let's create an just a here.
So we're going to assign it just an integer, but we will create an array, for example, one, two,
three, four and five.
And here we're going to create a pointer, a here named point P A, and we assign this to A and I will
explain all this codes here, of course, as I do always and here, point array, the reference point
array and your 11 assignment 11.
And here a one year 12.
And.
T.
A.
Two year equals sign at 13.
And here the reference for the referencing operator here and P a plus three and sign it 14 here, for
example.
So let's run our code before.
Of course, we have to write the print statements here.
So the first line here allocates an array of five integer.
On the stack and initializes the values of the number from from 1 to 5.
In this example, because an initialization list is used, the compiler will create a space for the
required number of items and the size of the array is not given.
So if you give the size of the array between the bracelets here, then the initialization list must
not have more items than the array size.
So if the list has fever items, then the rest of the items in the array are initialized to the default
value, usually zero.
So the next line in this code here.
Octane is a pointer to the first items in the array, so this lines after array items in various ways.
So the first of these p a changes the first item in the lines, first item in the array by referencing
the pointer and assigning it a value here the second here.
You know, here the second year uses indexing, but this time with a pointer and size of value to the
third value in array.
So and the final example here, as you can see here, this expression uses a pointer arithmetic to determine
the address of the fourth item in the array.
So remember, the first item was index of zero here.
So and the reference is the pointer to assign the item value.
After this, the array contains here, here, after.
After all of this here array contains 11, 12, 13, 14, and five.
So.
Now I want to illustrate this for more example.
So actually let me create a diagram for it and I will show you what we did here.
Here.
This is an example of what we did here with this code here.
So basically this code, we write it here does this illustration as I diagram, as I draw it here so
you can wash and just illustrated by your own.
So if you have a memory buffer, which now we're going to.
Try the second example here with C++ pointers.
So if you have a memory buffer containing values in this in this example, I'll look at an array and
you want to multiply each value by three.
You can do using the pointer arithmetic.
So let's create an example here.
So like this comment.
Four.
We will use the four loop here.
Integer E or integer A.
Actually, let's create a new integer here.
Integer.
Compare.
Or we can create an integer in this function integer E here zero.
We will assign it first with zero, and while it's less than five, then increment integer E by one
here plus plus e here.
And then we're going to use the pointer arithmetic to increase its value by one here.
So the loop statement is complicated and you will need to refer back to the operator presence in this
lecture here.
So the post effects increment operator has the highest precedence.
The highest presence is the reference operator here.
And finally, this operator has the lowest of the three operators.
So the operations are run in order.
The first.
Then this.
And the lastly this.
So the post fix operator returns the value before the increment.
So although the pointer is incremented so that the next item in memory, the expression uses the others
before the increment.
So this address is the reference set which is assigned by the assignment operator that replaces the
item with the value multiplied by three.
So this illustrates an important difference between pointers and array names.
So you can increment a pointer, but you cannot increment an array.
So let's so you can do this here.
For example, p a plus equals increment by one statement here and you can do this with pointers, but
you cannot do this with arrays here.
One.
Cannot hear or error here.
As you can see here, you will get an error because invalid operands to binary expressions.
And actually you can, of course, use the indexing with this.
Both on arrays and pointers here.
Let's this comment.
If you download this code in the lecture section and you can use it, of course, and you can play with
this pointers in your own time.