| C++ Program Design, 3/e James P. Cohoon,
University of Virginia Jack W. Davidson,
University of Virginia
Pointers and dynamic memory
Chapter 11 OverviewMany problem solutions require that a significant amount of information be
represented. These tasks can be accomplished with C++ mechanisms that
provide for the dynamic creation and management of objects during run time.
Such mechanisms allow programs to be flexible and to represent arbitrarily
sized data instances. Dynamic objects are created using the new operator and
are returned to the system using the delete operator. Access to a dynamic
object is through a pointer, where a pointer is an object whose value is the
location of another object. Pointers have similarities to iterators. In fact, an
iterator can be viewed as a pointer abstraction. To support pointers, C++
provides two complementary operators—the address operator & and the
dereferencing operator *. The address operator allows the location of an object
to be computed, and the dereferencing operator allows the value stored at a
location to be computed. Our discussion begins with pointers. |
|