Dereferencing deleted pointers always result in an Access Violation?

后端 未结 6 2069
情话喂你
情话喂你 2020-11-30 13:51

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

6条回答
  •  难免孤独
    2020-11-30 14:34

    The executable with debug symbols is able to detect some cases of access violations. The code to detect this is contained in the executable, but will not be triggered by default.

    Here you'll find an explanation of how you can control behaviour outside of a debugger: http://msdn.microsoft.com/en-us/library/w500y392%28v=VS.80%29.aspx

提交回复
热议问题