C arrays do not have border checks.
Like others, you click on undefined behavior; until you stay within the boundaries of the array, everything will be fine. If you cheat on the standard, anything can happen, including your program, it seems to work correctly, as well as the explosion of the Sun.
What happens in practice is that with the variables associated with the stack, you are likely to overwrite other variables in the stack, getting "impossible" errors, or if you press the canary value set by the compiler, it can detect overflow buffer upon return from function. For variables allocated in the so-called heap, the heap allocator may have given more space than requested, so an error can be less easily detected, although you can easily spoil the internal structures of the heap.
In both cases, you can also get to the protected memory page, which will force your program to stop (this is less common for the stack, because you usually have to rewrite the entire stack to go to the protected page).
source share