问题
Why does int arr[2]={10,20,30,40,50}
leads to error?
Why can't this initialization escape error by Array Bound Checking?
int arr[2] ;
arr[0]=10, arr[1]=20, arr[3]=30, arr[4]=40;
Doesn't cause error in context to C language by array bound checking?
回答1:
There is no runtime array bounds check in C. You are free to obliterate whatever is in memory. The 1st example you show, is a compile-time structure, so the compiler know that you declared an array of size 2, and that the initialization has > 2 elements.
来源:https://stackoverflow.com/questions/46144353/how-does-below-method-of-array-initialization-differ-in-context-to-array-bounds