sub1 ampx void sub1 int pint pint pint 25 100 pint x ampx pint or dereferenced value of pint is the value of what pint points to 100 125 passing the address of x ID: 366487
Download Presentation The PPT/PDF document "int x = 100;" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
int x = 100;sub1 (&x);void sub1 (int *pint){ *pint = *pint + 25;}
100
pint
x
&x
pint
or
de-referenced value of pint is the
value of
what pint points to
100
125
passing the address of x
Example 1Slide2
int x = 100;int *p = &x;sub1 (p);void sub1 (int *pint){
*pint = *pint + 25;}
100
pint
x
p
de-referenced value of pint is the value of what pint points to
100
125
passing the
value
of p which is the address of x
Example 2Slide3
int x = 100;int *p = &x;sub2 (&p);void sub2 (int **ppint
){
**ppint = **
ppint + 25;
}
100
ppint
x
p
double de-referenced value of
ppint
is the value of the value of what
ppint points to
100
125
passing the
address
of p
Example 3Slide4
int x = 100;int *p = &x;sub2 (&p);void sub2 (int **ppint
){
*ppint =
malloc(
sizeof(int));
**ppint = 50;
}
100
ppint
x
p
double de-referenced value of
ppint
is
the value of the value of
what
ppint
points to
passing the
address
of p
single de-referenced value of
ppint
is
the value of
what
ppint
points to. In this case, we are assigning a value to what
ppint
points to.
malloc-ed
50
Example 4Slide5
int x = 100;int *p = &x;sub2 (&p);void sub2 (int **
ppint){
ppint
= malloc
(sizeof
(int));
*ppint
= 50;}
100
ppint
x
p
single de-referenced value of
ppint
is
the value of
what
ppint
points to
passing the
address
of p
no de-referencing !! What is this changing?
malloc-ed
50
Example 5
ppint
itself