Title: Data Structure
1Data Structure Algorithm
2Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- As a starting point, consider the simple C code
above
3Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- The statement int i 10 is used to define one
variable named i with type of integer and value
is 10
4Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- At this point we might agree that there are only
two entities exist with that single statement
which are i and its value 10
5Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- Below is the possible output of the program10
- 0xfeed4d84
6Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- From the output we know that there are other
entity which is 0xfeed4d84
7Introduction to Pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt i ltlt "\n" cout
ltlt i ltlt "\n" return 0
- Right now we should know that there are three
entities exist with that single statement which
are i, 10 and 0xfeed4d84
8Introduction to Pointer
- To better understand this situation we could try
to imagine that the computer main memory (RAM)
may could be represented as a table below
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfeed4d84 10
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
9Introduction to Pointer
- Each time variable is defined it will be set by
the system to refer to some address in the
computer main memory
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfeed4d84 10
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
10Introduction to Pointer
- We can conclude that variable i is used to refer
to the address 0xfeed4d84 in the main memory
which store the value of integer 10
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfeed4d84 10
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
11Introduction to Pointer
- This is the nature for most of programming
languages where its easy to get back the value
of 10 from the memory by remembering i instead
of 0xfeed4d84
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfeed4d84 10
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
12Introduction to Pointer
- Base on our new level of understanding we might
want to refine the previous simple C code as
below
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" return 0
13Introduction to Pointer
- Also note that i is a syntax if we want to get
the address referred by the variable i and its
also applied to other type of variables (char,
float, double)
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" return 0
14Introduction to Pointer
- Before go further you should try to make your own
- conclusion by answering the following questions
-
- What are variable, address, value and memory?
- How to get the address of particular defined
variables?
15Introduction to Pointer
- Base on the C code below we know that we can
print out the address of i
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" return 0
16Introduction to Pointer
- Can we store the address of i into other
variable?
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" return 0
17Introduction to Pointer
- You could try by adding a few lines of code
below.
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
18Introduction to Pointer
- At the compilation time (linux) you might get the
errorerror invalid conversion from int to int
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
19Introduction to Pointer
- It is due to the fact that variable p is declared
to store the value of integer and not the address
of memory that store integer value
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
20Introduction to Pointer
- To declare p so it can store the address of
memory that store integer value just change the
statement from int p to int p
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
21Introduction to Pointer
- To declare p so it can store the address of
memory that store integer value just change the
statement from int p to int p
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
22Introduction to Pointer
- Print out the information for p by using the
pattern we print out the information for i
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i return 0
23Introduction to Pointer
- Try print out the information of p by using the
pattern we print out the information of i
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i cout ltlt Value
of p ltlt p ltlt "\n" cout ltlt Address of p
ltlt p ltlt "\n" return 0
24Introduction to Pointer
- The possible output may look like below
Value of i 10 Address of i 0xbfe35f9c
Value of p 0xbfe35f9c Address of p 0xbfe35f98
25Introduction to Pointer
- Notice that Address of i and Value of p got the
same number which is 0xbfe35f9c
Value of i 10 Address of i 0xbfe35f9c
Value of p 0xbfe35f9c Address of p 0xbfe35f98
26Introduction to Pointer
- To get a better understanding, create a table
that representing the current state of main
memory for this situation
Value of i 10 Address of i 0xbfe35f9c
Value of p 0xbfe35f9c Address of p 0xbfe35f98
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
27Introduction to Pointer
- i is an integer and p is a pointer that store the
address referred by i
Value of i 10 Address of i 0xbfe35f9c
Value of p 0xbfe35f9c Address of p 0xbfe35f98
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
28Introduction to Pointer
- Its possible to access the value of i via p
cout ltlt Value of i via p is ltlt p ltlt
"\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
29Introduction to Pointer
- This is what we call pointer dereferencing as it
will refer to the address stored by the pointer
cout ltlt Value of i via p is ltlt p ltlt
"\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
30Introduction to Pointer
- This is what we call pointer dereferencing as it
will refer to the address stored by the pointer
cout ltlt Value of i via p is ltlt p ltlt
"\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
31Introduction to Pointer
- Its also possible to change the value of i by
dereferencing p
p 20 cout ltlt Value of i after p
20 is ltlt i ltlt "\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
32Introduction to Pointer
- Its also possible to change the value of i by
dereferencing p
p 20 cout ltlt Value of i after p
20 is ltlt i ltlt "\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
33Introduction to Pointer
- Its also possible to change the value of i by
dereferencing p
p 20 stdcout ltlt Value of i after
p 20 is ltlt i ltlt "\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 10
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
34Introduction to Pointer
- Its also possible to change the value of i by
dereferencing p
p 20 stdcout ltlt Value of i after
p 20 is ltlt i ltlt "\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
35Introduction to Pointer
- Its also possible to change the value of i by
dereferencing p
p 20 stdcout ltlt Value of i after
p 20 is ltlt i ltlt "\n"
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
36Introduction to Pointer
- The program that we should have so far to
understand the pointer
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i cout ltlt Value
of p ltlt p ltlt "\n"cout ltlt Address of p
ltlt p ltlt "\n" cout ltlt Value of i via p is
ltlt p ltlt "\n" p 20 cout ltlt Value
of i after p 20 is ltlt i ltlt
"\n" return 0
37Introduction to Pointer
- Notice that after i and p are defined they are
called with different approaches/manners which
are i, i, p, p, and p
include ltiostreamgt using namespace std int
main() int i 10 cout ltlt Value of i
ltlt i ltlt "\n" cout ltlt Address of i ltlt i
ltlt "\n" int p p i cout ltlt Value
of p ltlt p ltlt "\n"cout ltlt Address of p
ltlt p ltlt "\n" stdcout ltlt Value of i via
p is ltlt p ltlt "\n" p 20 stdcout ltlt
Value of i after p 20 is ltlt i ltlt
"\n" return 0
38Introduction to Pointer
- Using the table of memory below we can visualize
what i, i, p, p, and p are all about
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
39Introduction to Pointer
- There is no i as i is not a pointer
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
40Introduction to Pointer
- The pointer p can also be assigned with the
memory address allocated without using any
defined and named variable such as i
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
41Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as follows
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
42Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
43Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
. . . . . . . . . . . .
. . . . . . . . . . . .
44Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
45Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
46Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
47Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f9c
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
48Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
49Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
50Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new int
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
51Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new intp 30
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
52Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new intp 30
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? ???
. . . . . . . . . . . .
53Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new intp 30
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
54Introduction to Pointer
- This technique referred as a dynamic memory
allocation and can be applied as followsp
new intp 30
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
55Introduction to Pointer
- Beware that the address 0xbfe35f?? is allocated
using dynamic memory allocation so it doesnt
have any defined variable referring to it
(variable name assign with ???)
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
56Introduction to Pointer
- If the program stop right now, the operating
system aware and able to release/freeing the
memory space at 0xbfe35f9c and 0xbfe35f98 as it
was formally defined and named with i and p
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
57Introduction to Pointer
- Its not the same for 0xbfe35f?? as it was
allocated using dynamic memory allocation and
require the programmer manually release/freeing
it
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
58Introduction to Pointer
- It can be done by using delete function and set p
to NULL as below each time before the program
exit
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
59Introduction to Pointer
- It can be done by using delete function and set p
to NULL as below each time before the program
exit delete p
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
??? int 0xbfe35f?? 30
. . . . . . . . . . . .
60Introduction to Pointer
- It can be done by using delete function and set p
to NULL as below each time before the program
exitdelete p
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
. . . int 0xbfe35f?? 0
. . . . . . . . . . . .
61Introduction to Pointer
- It can be done by using delete function and set p
to NULL as below each time before the program
exit delete pp NULL
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 0xbfe35f??
. . . int 0xbfe35f?? 0
. . . . . . . . . . . .
62Introduction to Pointer
- It can be done by using delete function and set p
to NULL as below each time before the program
exitdelete pp NULL
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c 20
p int 0xbfe35f98 NULL
. . . int 0xbfe35f?? 0
. . . . . . . . . . . .
63Introduction to Pointer
- Is the current situation below is valid or
allowed?
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c ???
p int 0xbfe35f98 0xbfe35f??
f float 0xbfe35f?? ???
. . . . . . . . . . . .
64Introduction to Pointer
- It is not valid or allowed as p is defined to
only hold the address of integer while 0xbfe35f??
is the address of float
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c ???
p int 0xbfe35f98 0xbfe35f??
f float 0xbfe35f?? ???
. . . . . . . . . . . .
65Introduction to Pointer
- This situation can be experimented by adding the
following lines of code and will get an error at
compilation timefloat f 1.7p f
p
p
i
p
i
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xbfe35f9c ???
p int 0xbfe35f98 0xbfe35f??
f float 0xbfe35f?? ???
. . . . . . . . . . . .
66Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
below
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
67Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
belowint p2
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
68Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
belowint p2
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
p2 int 0xbfe35f?? . . .
69Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
belowint p2 p2 p
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
p2 int 0xbfe35f?? . . .
70Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
belowint p2 p2 p
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
p2 int 0xbfe35f?? 0xfe35f9c
71Introduction to Pointer
- In certain circumstances it also possible to have
two pointer that point to the same address as
belowint p2 p2 p
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
p2 int 0xbfe35f?? 0xfe35f9c
p2
72Introduction to Pointer
- Using the memory of table like below might help
us to better understand the pointer but its not
practical for complex data type such as class
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
73Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
74Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
75Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
i
20
76Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
i
20
77Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
i
20
p
.
78Introduction to Pointer
- We can simplify it as follows
p
Variable Name Type Address Value
. . . . . . . . . . . .
i int 0xfe35f9c 20
p int 0xbfe35f98 0xfe35f9c
. . . . . . . . . . . .
i
20
p
.
79Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
80Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
81Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
p2
.
temp
.
82Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
p2
.
temp
.
83Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
temp
.
84Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
temp
.
85Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
temp
.
86Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
temp
.
87Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
temp
.
88Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
89Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
90Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
91Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
92Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
93Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
94Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
95Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
???
temp
.
96Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
97Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
98Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
99Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
100Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
101Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
102Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
103Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
104Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
105Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
106Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
107Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
108Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temp temp NULL
p
.
i
10
p2
.
???
30
temp
.
109Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temptemp NULL
p
.
i
10
p2
.
???
30
temp
.
110Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temptemp NULL
p
.
i
10
p2
.
???
30
temp
.
111Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temptemp NULL
p
.
i
10
p2
.
???
30
temp
.
112Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temptemp NULL
p
.
i
10
p2
.
???
30
temp
.
113Introduction to Pointer
- Now you should able to understand basic pointer
operations below by using the simplified version
of pointer representation technique explained in
the previous slide int p, p2, temp int
i 10 p ip2 new intp2 30temp
pp p2p2 temptemp NULL
p
.
i
10
p2
.
???
30
temp
.
114Conclusion
- Each time we declare variable there are three
main entities exist which are the variable name,
its value, and address in memory referred by the
variable - We can get the address of variables by using the
syntax var_name - There is special variable which is called as
pointer that can store/hold address referred by
other variables - For variable of type pointer declare as T P, P
can only store address referred by other
variables with type T - Dereferencing is the term used to access the
value of other variable point by the pointer