Array index out of bound in C

后端 未结 10 1115
抹茶落季
抹茶落季 2020-11-21 21:58

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         


        
10条回答
  •  再見小時候
    2020-11-21 22:48

    C isn't doing this. The OS's virtual memeory subsystem is.

    In the case where you are only slightly out-of-bound you are addressing memeory that is allocated for your program (on the stack call stack in this case). In the case where you are far out-of-bounds you are addressing memory not given over to your program and the OS is throwing a segmentation fault.

    On some systems there is also a OS enforced concept of "writeable" memory, and you might be trying to write to memeory that you own but is marked unwriteable.

提交回复
热议问题