Let us suppose the following piece of code:
#include <stdio.h>
int main(){
int array[3] = {1,2,3};
printf("%d\n",array[-1]);
printf("%d\n",array[4]);
return 0;
}
In the two printfs I'm accessing out-of-bounds positions of the array. Is there any difference in the kinds of errors generated in the two situations?
I have seen in some discussions that accessing positions before zero can produce a segmentation fault or printf can print undefined values. On the other hand, some people say that segmentation fault is not possible to happen when accessing positions after the last valid position, due to the way the operating system manages the memory. Is this correct?
And what can happen in embedded systems, without an OS?