strcpy doesn't crash despite not enough char array elements
Why doesn't strcpy crash in the following sequence? I have declared a new char array with zero elements into which I am copying 5 characters.
1 2 3 4 5
|
#include <iostream>
char* buffer = new char[0];
strcpy(buffer, "Hello");
cout << buffer << endl;
|
Undefined behaviour does not necessarily result in a crash.
Though, we would all be better off, if it did.
Topic archived. No new replies allowed.