Dereferencing deleted pointers always result in an Access Violation ??

Posted by m3rLinEz on Stack Overflow See other posts from Stack Overflow or by m3rLinEz
Published on 2010-05-24T10:29:53Z Indexed on 2010/05/24 10:31 UTC
Read the original article Hit count: 182

Filed under:
|
|
|
|

I have a very simple C++ code here:

char *s = new char[100];
strcpy(s, "HELLO");
delete [] s;
int n = strlen(s);

If I run this code from Visual C++ 2008 by pressing F5 (Start Debugging,) this always result in crash (Access Violation.) However, starting this executable outside the IDE, or using the IDE's Ctrl+F5 (Start without Debugging) doesn't result in any crash. What could be the difference?

I also want to know if it's possible to stably reproduce the Access Violation crash caused from accessing deleted area? Is this kind of crash rare in real-life?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++