在下面的代码的,我已经分配的值到一个数组元件,其出数组界限,在Linux的环境在CLI代码给我错误消息:array index 5 is past the end of the array which contains 5 elements
。阵列:出索引/边界
但在IDE上调试时 codeblocks -compiler找不到这个bug-那么有什么解释吗?
#include <stdio.h>
int main()
{
int array[5],i;
for (i=0; i<5; i++) {
array[i] = i+1;
}
array[5] = 666;
for (i=0; i<5; i++) {
printf("array[%d]=%d\n", i, array[i]);
}
printf("array[5]=%d\n", array[5]);
return 0;
}
在数组边界之外使用指示符是[未定义的行为](https://www.google.pl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=c%20undefined%20behavior )。除了任何IDE都不能做任何事情。 – Crozin
codeblocs的编译器是什么? – LPs
想想** undefined ** _behaviour_的含义。 – Olaf