可以在c中的运行时确定数组的大小吗? [英] can size of array be determined at run time in c?

查看:25
本文介绍了可以在c中的运行时确定数组的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在 c 中编译时间之前,数组需要具有特定大小.

As I know, an array needs to have a specific size before compiling time in c.

我想知道为什么这段代码仍然有效?

I wonder why this code still works?

int s;
printf("enter the array size: ");
scanf("%d",&s);

int a[s]; // Isn't s value determined at run time?

推荐答案

ANSI 89 C 需要知道数组大小.规范的 99 版本取消了这个限制,并允许可变大小的数组.

Array sizes need to be known with ANSI 89 C. The 99 version of the spec removed this limitation and allowed for variable sized arrays.

这里是文档,没有这个功能的 GNU 版本

Here is the documentation no the GNU version of this feature

这篇关于可以在c中的运行时确定数组的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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