为什么[N]是在C运行期间接受? [英] why a[n] is accepted in c during runtime?

查看:98
本文介绍了为什么[N]是在C运行期间接受?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们为什么能做到这一点在C?

why can we do this in c?

int n;
scanf("%d",&n);
int a[n];

我想在加载时间阵列位于内存,但似乎像上面的例子中运行时的工作原理。
难道我误解了什么事儿?你们可以帮忙吗?

I thought array is located memory during load time but seems like the above example works during runtime. Do I misunderstand any thing? can you guys help?

谢谢,

推荐答案

我以为数组是*人*在加载时位于内存,但似乎像上面的例子在运行时的工作原理。

是的,普通数组一样<数据类型> <&ARRAY_NAME GT; [<大小>。中加载时间分配的内存是在有C89和C99也存在

Yes, ordinary arrays like <datatype> <Array_Name> [<size>] is allocated memory during load time it is there in C89 and also existed in C99.

但在code段 int类型的[N]; 在C99变长数组或对VLA short.VLA的只是像任何其他数组定义,除了长度并不需要是一个编译时间常数

But in the code snippet int a[n]; is a Variable Length Array or VLA for short.VLA's in C99 are defined just like any other array, except that the length doesn’t need to be a compile-time constant.

在沃拉斯需要一个像样的文章可以在这里找到:HTTP://www.ddj.com/cpp/184401444:)

A decent article on the need of VLAs can be found here :http://www.ddj.com/cpp/184401444 :)

这篇关于为什么[N]是在C运行期间接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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