Why does C
differentiates in case of array index out of bound
#include
int main()
{
int a[10];
a[3]=4;
a[11]=3;//doe
You generally only get a segmentation fault if you try to access memory your process doesn't own.
What you're seeing in the case of a[11]
(and a[10]
by the way) is memory that your process does own but doesn't belong to the a[]
array. a[25000]
is so far from a[]
, it's probably outside your memory altogether.
Changing a[11]
is far more insidious as it silently affects a different variable (or the stack frame which may cause a different segmentation fault when your function returns).