CPS 6, Ramm - Spring 2000 - 4/14/00, #34
- Announce
- Quiz Today
- (Due date on Assignment was set to Fri, 4/21)
12. Dynamic Data, List, & Class Templates
- Motivation for Pointers
- More precise control of memory allocation
- (Vectors were doubled on resizing)
- Provide indirect references for sharing
- Linked Data Structures need pointers
- Pointers as Indirect References
- Pointer holds a memory address
- Pointer refers to something indirectly
- analogy: Indexes, Directories, Mail Addresses
- Pointer Definition Syntax
- int * p;
- Dice * diePtr;
- string * strP;
- Pointers as References
- address: below the surface
- * dereference operator
- & address-of operator
- Examples
- Pointer uses (conceptual)
- Tag Sorts
- Sort list by more than one key
- Pointers as Parameters
- swap using reference parameters
- swap using pointers (C style)
- The
new Operator
- Simple Examples
- The Selector Operator
->
- Used to access members of structs or classes
- Another Example
- Implementing a Tag Sort
- Use a vector of pointers
- Modify Selection Sort
- Linked Lists
- Pointer Diagrams
- Conceptual
- The Null Pointer
- The Five Ways to Assign a Value to a Pointer
- Assign value generated by
new operator
- Assign value generated by the address of (
&) operator
- Assign value from another pointer
- Assign value returned by a function
- Assign the special value 0 or
NULL