Why does C/C++ differentiate in case of an array index out of bound?
#include <stdio.h>
int main()
{
int a[10];
a[3] = 4;
a[11] = 3; // Does not give a segmentation fault
a[25] = 4; // Does not give a segmentation fault
a[20000] = 3; // Gives a segmentation fault
return 0;
}
I understand that it's trying to access memory allocated to a process or a thread in case of a[11] or a[25] and it's going out of stack bounds in case of a[20000].
Why doesn't the compiler or linker give an error? Aren't they aware of the array size? If not, then how does sizeof(a) work correctly?