Why does not my program go into infinite loop when array out of bounds occur in C

前端 未结 2 1208
遥遥无期
遥遥无期 2021-01-27 03:38
int main(){
   int i;
   int arr[4];
   for(int i=0; i<=4; i++){
      arr[i] = 0;
   }
   return 0;
}
  1. I watched a video on youtube of CS107(l
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-27 03:57

    When there is undefined behavior you can't expect a single or particular behavior. Anything could happen.
    What said in that video is just one of many possibilities of undefined behavior and what you are getting is another possibility. One should not rely upon any particular behavior.

提交回复
热议问题