An object variable contains an object, but a pointer specifies where an
object is located.
In C++, pointers are important for several reasons.
Pointers can refer to objects that are dynamically allocated whenever they are
needed.
Pointers can be used for shared access to objects.
Furthermore, as you will see, pointers are necessary for implementing
polymorphism,
an important concept in object-oriented programming.
In C++, there is a deep relationship between pointers and arrays. You will see
how this relationship
explains a number of special properties and limitations of arrays.
Finally, you will see how to convert between string objects and char* pointers,
which is necessary when
interfacing with legacy code.
Goals:
1. To learn how to declare, initialize, and use
pointers
2. To become familiar with dynamic memory allocation and de-allocation
3. To use pointers in common programming situations that involve optional and
shares objects
4. To avoid the common errors of dangling pointers and memory leaks
5. To understand the relationship between arrays and pointers
6. To be able to convert between string objects and character pointers
1. Pointer operators (read 5.3)
Example 1
Fig05_04.cpp
Explain the output
Example 2
pointers.cpp
(Unix Makfile pointers.make)
Explain the output, Draw the identifiers and their values as they are
arranged in memory .
2. Calling functions by reference (read 5.4)
Example 3
Fig05_06.cpp
Example 4
Fig05_07.cpp
3. Using const with pointers (read 5.5)
Example 5
Fig05_10.cpp
Example 6
Fig05_11.cpp
Example 7
Fig05_12.cpp
Example 8
Fig05_13.cpp
Example 9 (bubble sort)
Fig05_15.cpp
4. Relationship between Pointers and Arrays (read 5.8, 5.9)
Example 10
Fig05_20.cpp
Example 11 (Arrays of Pointers)
Fig05_21.cpp
5. Function Pointers (read 5.11)
Example 12
Fig05_26.cpp
6. Relationship between Pointers and Arrays (read 5.12)


Example 14
Fig05_28.cpp
Example 15
Fig05_30.cpp
Example 16
Fig05_31.cpp
Example 17
Fig05_32.cpp
Exercise A2Q3, A2Q4
practice.cpp