D
divya_rathore_
Old question in a new bottle:
What if i delete a 1D array and again use new to allocate a bigger (or
smaller) size?
is this ok? Feel free to shoot me!
int *array;
int size = 100;
//allocate memory for 'size' no of integers.
array = new int[size];
//fill up the 'array'.
for (int i=0; i<100; i++) array = i;
//delete data pointed to by 'array'
delete[] array;
//again allocate but a bigger size!!
//is this ok??
array = new int[200];
//fill up the 'array'.
for (int i=0; i<200; i++) array = i;
//delete data pointed to by newly allocated 'array'
delete[] array;
Compiler specifics: Microsoft visual studio ver 6.0 and higher.
What I know: it can be done using STL, I KNOW. But how right/wrong is
the above approach?
What if i delete a 1D array and again use new to allocate a bigger (or
smaller) size?
is this ok? Feel free to shoot me!
int *array;
int size = 100;
//allocate memory for 'size' no of integers.
array = new int[size];
//fill up the 'array'.
for (int i=0; i<100; i++) array = i;
//delete data pointed to by 'array'
delete[] array;
//again allocate but a bigger size!!
//is this ok??
array = new int[200];
//fill up the 'array'.
for (int i=0; i<200; i++) array = i;
//delete data pointed to by newly allocated 'array'
delete[] array;
Compiler specifics: Microsoft visual studio ver 6.0 and higher.
What I know: it can be done using STL, I KNOW. But how right/wrong is
the above approach?