This is undefined behavior . You can never predict when (or, if at all) it will work, but you cannot rely on it to “fail” and the application code.
Reasoning
The rationale is that in c arrays there is no compilation or runtime "index from linked check". This is present in STL vectors or arrays in other higher-level languages. Therefore, whenever your program accesses memory outside the allocated range, it depends on whether it simply distorts another field in your program stack or affects the memory of another program or something else, so it is impossible to predict a failure that only occurs in extreme cases. It is only a failure in a state that causes the OS to intervene or when it no longer remains possible for your program to function correctly.
Example
Say that you were inside the function call, and right next to your array was the address RETURN, that is, the address that your program uses to return to the function from which it was called. Suppose you mess this up, and now your program is trying to return to a damaged value that is not a valid address. Consequently, in such a situation he would have collapsed.
The worst happens when you tacitly modify a different field value and don't even find out what was wrong if there was no failure.
source share