Please send questions to
st10@humboldt.edu .
(finished ptr_play1.cpp)
(did a little function-with-a-pointer-parameter
example, get_double_at)
DYNAMIC memory allocation
* the new operator, when followed by the name
a type, allocates a chunk of memory from
the freestore or heap and produces/returns
the address of that chunk of memory;
new double // allocates a chunk of memory able to hold
// a value of type double, and has as its
// value the address of that chunk of memory
new int
new boa
Say that I have:
int *num_ptr;
num_ptr = new int;
*num_ptr = 84; // now that chunk of freestore
// contains 84
BUT!!!!! What you have ALLOCATED with new,
YOU ARE EXPECTED TO FREE, or release, or clean up,
using:
delete
For example, here:
delete num_ptr;
YES, THIS IS A CLASS CODING STANDARS
ALSO:
once you have freed what a pointer is pointing to,
it is a good habit to then set that point to NULL:
delete num_ptr;
num_ptr = NULL;
* see ptr_play2.cpp