Delete in middle of array
What is the result of the following:
1 2
|
char* str = new char[200];
delete [] &str[100];
|
does it delete the whole array? or only half of it?
Thank you!
It's undefined behavior. It will likely corrupt your memory, crash your program or do nothing.
damn I don't like any of that...
Thanks for the answer!
Last edited on
No. Do not do this, it is undefined behavior.
Always, always, ALWAYS use delete[] for every new[].
1 2
|
char *str = new char[200]
delete[] str;
|
This methodology the ONLY proper way to use delete[].
Topic archived. No new replies allowed.