size of delete[]

int *ptr = new int[10];

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

but, delete[] ptr; without indicating size ?
implementation save size of allocated memory and delete[] uses it.
another question
1
2
for(int obj: ptr)
     cout << obj << " ";

does not work!
works for array. not for pointer?
No. As it is pointer, not an array.
You should not use raw arrays anyway. Prefer C++ container classes: std::vector, std::array...
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.