just getting back to programming and want to check new and delete operators,
are the following code snippet and comments correct, also the storage duration
of the new object is from its creation up unto delete or end of program which
in the latter case I would get a memory leak(I think) without delete.
I know this code is not practical, for a start I would need to see if there
is enough memory available to create the new object, are dynamic objects
created from the stack or the heap, its my understanding that they are
created on the heap to save room on the stack.
could you also point me in the right direction for a full explanation
of the stack and the heap.
also would I delete a dynamic array like so deletearray_name;
int *age_ptr; /* pointer of type int */
age_ptr = new int; /* age_ptr points to a new object of size\int */
/* and is identified by the name, name_ptr */
age_ptr = 39; /* the new dynamically created objects value is now 39 */
delete age_ptr; /* destoy\free the memory on the new object */
printf("\n\n%d",*age_ptr); /* this still outputs 39 because the memory has'nt */
/* been overwriten just freed */
and how about a multidimentional array.
I know this is a lot of questions but I really appreciate all
your guidence thank you.
Please use [code][/code]Tags