size of delete[]

Nov 10, 2014 at 8:21am
int *ptr = new int[10];

for(...) // this loop does not know the size of ptr

but, delete[] ptr; without indicating size ?
Nov 10, 2014 at 8:33am
implementation save size of allocated memory and delete[] uses it.
Nov 10, 2014 at 9:51am
another question
1
2
for(int obj: ptr)
     cout << obj << " ";

does not work!
works for array. not for pointer?
Nov 10, 2014 at 10:06am
No. As it is pointer, not an array.
You should not use raw arrays anyway. Prefer C++ container classes: std::vector, std::array...
Nov 10, 2014 at 12:37pm
it seams there is a table that saves the size of the block allocated use new or new[],
as a programmer, you needn't to care about it.
Topic archived. No new replies allowed.