太多的数组中的元素! [英] Too many elements in an array!

查看:99
本文介绍了太多的数组中的元素!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一个noob问题:(。

Sorry if this is a noob question :( .

C $ C $的c片。

Piece of C code.

int array[5];
int cnt;

for(cnt = 0; cnt <= 10; cnt+=1)
{
      array[cnt] = cnt;
}

应该给一个错误,对不对?没有!做工精细!
但是,这是为什么?似乎-in第一LINE-比双尺寸以上的阵列(11)被定义。你甚至可以访问阵列[5-10]以后。这是混淆了我。它停止工作,当你定义数组[4个或更少] ...

Should give an error, right? No! Works fine! But why is that? It seems that -in the first line- an array of more than the double size (11) is defined. You can even access array[5 to 10] later on. And that is confusing me. It stops working when you define array[4 or less] ...

先谢谢了。

推荐答案

它可能发生与特定​​的编译器和计算机工作,但你不应该指望它。

It may happen to work with your particular compiler and computer, but you shouldn't count on it.

根据C语言规范中的code的行为的未定义的。这意味着它可能做你希望的东西,也可能导致您的计算机崩溃,或者可能引起的恶魔飞出你的鼻子

The behaviour of your code according to the C language specification is undefined. This means that it might do what you hope, or it might cause your computer to crash, or it might cause demons to fly out your nose.

不像高级语言如Java和C#,C相信你和阵列的界限不明确执行检查。你应该负责,而不是蹬数组的边界之外。

Unlike higher-level languages such as Java and C#, C trusts you and does not perform explicit checks on the bounds of arrays. You are supposed to be responsible and not tread outside the boundaries of the array.

这篇关于太多的数组中的元素!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆