Beruflich Dokumente
Kultur Dokumente
POINTER
Chapter 8. POINTER
Minh Quang NGUYEN
Hanoi National University of Education
September 2015
Paris Saclay
Chapter 8. POINTER
Introduction
Pointer Variables
Pointers and Arrays
Two-Dimensional Arrays
Initialization
You do it
Q&A
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
What is Pointer?
Pointers are the hobgoblin of C++ (and C) programming. Here
are some common uses:
I
Paris Saclay
Chapter 8. POINTER
Introduction
Paris Saclay
Chapter 8. POINTER
Introduction
Paris Saclay
10
Chapter 8. POINTER
Introduction
Paris Saclay
11
Chapter 8. POINTER
Introduction
Paris Saclay
12
Chapter 8. POINTER
Introduction
Paris Saclay
13
Chapter 8. POINTER
Introduction
Paris Saclay
14
Chapter 8. POINTER
Introduction
Example
Output
0x8f4ffff4 address of var1
0x8f4ffff2 address of var2
0x8f4ffff0 address of var3
Paris Saclay
15
Chapter 8. POINTER
Introduction
Note: variable is not at all the same as its contents. The contents
of the three variables are 11, 22, and 33.
Paris Saclay
16
Chapter 8. POINTER
Introduction
Note: variable is not at all the same as its contents. The contents
of the three variables are 11, 22, and 33.
Paris Saclay
17
Chapter 8. POINTER
Introduction
Paris Saclay
18
Chapter 8. POINTER
Introduction
Paris Saclay
19
Chapter 8. POINTER
Introduction
Paris Saclay
20
Chapter 8. POINTER
Pointer Variables
No Bounds Checking
Paris Saclay
21
Chapter 8. POINTER
Pointer Variables
Paris Saclay
22
Chapter 8. POINTER
Pointer Variables
Paris Saclay
23
Chapter 8. POINTER
Pointer Variables
Paris Saclay
24
Chapter 8. POINTER
Pointer Variables
Paris Saclay
25
Chapter 8. POINTER
Pointer Variables
Pointer to void
Paris Saclay
26
Chapter 8. POINTER
Pointer Variables
Example
ptrvoid
a pointer to void.
Paris Saclay
27
Chapter 8. POINTER
Pointers and Arrays
int intarray[5] =
int intarray[5] =
{ 31, 54, 77, 52, 93 };
{ 31, 54, 77, 52, 93 };
for(int j = 0; j < 5; j++)
for(int j = 0; j < 5; j++)
cout << intarray[j] << endl;
cout << *(intarray + j) << end
Paris Saclay
28
Chapter 8. POINTER
Pointers and Arrays
Paris Saclay
29
Chapter 8. POINTER
Pointers and Arrays
Paris Saclay
30
Chapter 8. POINTER
Pointers and Arrays
Paris Saclay
31
Chapter 8. POINTER
Pointers and Arrays
The reason...
I
The C++ compiler is smart enough to take the size of the data
into account when it performs arithmetic on data addresses.
Paris Saclay
32
Chapter 8. POINTER
Pointers and Arrays
The reason...
I
The C++ compiler is smart enough to take the size of the data
into account when it performs arithmetic on data addresses.
Paris Saclay
33
Chapter 8. POINTER
Pointers and Arrays
The reason...
I
The C++ compiler is smart enough to take the size of the data
into account when it performs arithmetic on data addresses.
Paris Saclay
34
Chapter 8. POINTER
You do it
Paris Saclay
35
Chapter 8. POINTER
Q&A
Paris Saclay
36