When I go beyond the border of the array, I do not get an error, but if I try to delete by the pointer, the program crashes. Why?
int main() { int * p = new int[5]; p[10] = 5; delete [] p; } You can spoil the service information of the memory manager, that's all. As a result, the memory manager is not able to correctly free up memory, and the system crashes.
Undefined behavior is so vague :). By the way, I recommend the book Safe Programming in C and C ++ - there is much to say about this (incorrect work with memory, which may be a vulnerability).
Because the indefinite behavior that occurs when writing outside the allocated memory can manifest itself quite differently. Including at later operations. This is the essence of UB (Undefined Behavior).
Source: https://ru.stackoverflow.com/questions/589133/
All Articles
p[10] = 5;the program can behave as it pleases, it is called UB. Fall, respectively, can at an arbitrary point in time. - andy.37