How does below method of array initialization differ in context to array bounds checking?

左心房为你撑大大i 提交于 2019-12-13 11:05:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!