FOR LOOP打印值大于没有核心转储的数组大小

时间:2018-07-31 13:18:49

标签: loops for-loop core dump

#include <stdio.h>
int main()
{
   int numbers[2]={0};
   int i=0;
   for(i=0;i<10;i++)
     {
       numbers[i]=1;
       printf("<%d>\n",numbers[i]);
     }
  return 0;
}

对于循环打印,如果输入小于3,则为无穷大值,它必须进行核心转储,因为数组的分配大小为2,最多可以包含3个值。没有收到核心转储。我不知道为什么,但是Loop会打印正确的值

1 个答案:

答案 0 :(得分:0)

根据ISO C标准,访问权限为Undefined Behavior.