下面的数组初始化方法在上下文和数组边界检查方面有何不同? [英] How does below method of array initialization differ in context to array bounds checking?

查看:67
本文介绍了下面的数组初始化方法在上下文和数组边界检查方面有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 int arr [2] = {10,20,30,40,50} 会导致错误?
为什么无法通过数组绑定检查来进行此初始化转义错误?

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;

通过数组绑定检查在C语言的上下文中不会引起错误吗?

Doesn't cause error in context to C language by array bound checking?

推荐答案

C中没有运行时数组边界检查。您可以随意清除内存中的任何内容。您显示的第一个示例是编译时结构,因此编译器知道您声明了一个大小为2的数组,并且初始化具有> 2个元素。

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.

这篇关于下面的数组初始化方法在上下文和数组边界检查方面有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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