delete, delete [] and delete [x] - what does x mean?

Hello everyone!

Here's the code:
1
2
3
4
5
char *c = new char[100];
int a;
for( a = 0; a < 100; a++ ) c[a] = 64;
delete [50] c;
cout << (int)c[51] << endl;


what this delete [50] c seems to do is that it deletes all 100 chars.
Why does my compiler allow to put a number into delete [here]?

I'm using Microsoft visual c++ 2010 express.
There's one other question.

If i do this char *c = new char[100];
can i delete just 50 from the end?
Can i delete some part of variable c without deleting all 100?

Thanks!
Can't reproduce this on my machine. TBH this is the first time I am seeing a number inside those square brackets for delete[]. My guess is that this is a visual c++ thing, and not standard.

Normally the delete[] operator will deallocate the memory associated with the array it was called on, but as for the value inside the brackets, I don't know how that affects the delete process
It is not valid C++ code. It is a Microsoft extension, and I am not sure what it does.

You cannot delete only part of an array - it's all or nothing.

By the way:
http://www.lb-stuff.com/pointers
Topic archived. No new replies allowed.