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

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

问题描述

据我所知,一个数组需要在C编译时间之前有一个特定的大小。

我不知道为什么这个code仍然有效?

  int类型;
的printf(请输入数组的大小:);
scanf函数(%d个,&安培; S);诠释一个[S]。 //是不是价值在运行时确定的?


解决方案

数组的大小必须与ANSI 89℃的99版本中删除此限制的规范是已知的,并允许可变大小的数组。

下面是文档没有GNU版本的这一功能

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?

解决方案

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.

Here is the documentation no the GNU version of this feature

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

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