This slide will help you to learn Pointer assignments, Pointer arithmetic,Pointer comparisons, Pointers & arrays, Arrays of pointers, Multiple indirection
2. Pointer assignments
Pointer arithmetic
Pointer comparisons
Pointers & arrays
Arrays of pointers
Multiple indirection
Pointers to function
Dynamic allocations
3. We know how to point a variable .
In this example I will show how to point a
variable from two pointers.
You must pass the vaddres1
to vAddress2.Because we
passed the address of
variable to vaddress1 not to
vAddress2
4. There are only two arithmetic operations that
you may use on pointers:
◦ Addition
◦ Subtraction
But you can do all operation on pointer’s
value as:
◦ Addition
◦ Subtraction
◦ Multiplication
◦ division
5. There are two type of comparison of pointers
◦ In between pointer = this is the comparison held
between the addresses they hold
If (p1>p2)
◦ In between pointer value = here we comparing
between the values they hold.
If (*p1>*p2)
6.
7.
8. you can direct a pointer to hold the array's address as
we do for a normal variable.
As I told you array is a sequence of similar type of
data type.
To hold the array's address when you direct the
pointer to hold array's address it holds the first’s of
that array address only.
To get the address of each element of array we have
to add the exact index number of that element. how
can we do that? we can do that with help of a loop or
directly adding the index’s number.
9. Int array[5]; Int array[5];
Int *Parray; Int *Parray;
Parray = array; Parray = &array[0];
10.
11.
12.
13. We already learned array of integers, array of
floats. As like those we have one type of array i.e.
Arrays of pointer.
Arrays of pointer will only hold a bunch of
addresses.
These addresses may be addresses of arrays or
may be addresses of different variables.
As for a integer type array compiler allocates
sequence of memory to store hold addresses.
14. When we create pointer array we have to
initialize the each element to direct to a
address.
The address may be a address of a variable or
an array. But they must be similar data type
of pointer array
int var1 = 400,var2 = 600;
int *arrpo[2];
arrpo[0] = &var1;
arrpo[1] = &var2;
15.
16.
17. We can say it point to pointer. It means we can
hold the address of a pointer as we hold the
address of the variable.
So when a pointer points to the address of a
variable we told it indirection. When another
pointer points to that pointer which points to a
variable is called multiple indirection.
int var;
int *fPointer,**spointer;
fpointer = &var;
spointer = &fpointer;
18. Pointer02 Pointer01 variable
• Address • Address • Value
19. When we have a pointer to a pointer the
pointer which will point to variable. We will
confuse with (*), (**) and (&). So do not
confuse with these.
var = gives value stored in var
int var; *fpointer = gives value stored in var
int *fPointer,**spointer; **spointer = gives value stored in var
fpointer = &var;
spointer = &fpointer;
*spointer = gives address of fpointer
&spointer = gives address of spointer
&fpointer = gives address of fpointer
&var = gives address of variable
20.
21. Even though a function is not a variable, it still
has a physical location in memory that can be
assigned to a pointer.
This address is the entry point of the function
and it is the address used when the function is
called.
Once a pointer points to a function, the function
can be called through that pointer.
Function pointers also allow functions to be
passed as arguments to other functions.