声明未知大小的数组 [英] Declaring an array of unknown size

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

问题描述

这是不特定于任何编程语言,问题是找一个指定的值的指数n个数的数组。

This is not specific to any programming language, the problem is "find the index of a specified value in an array of n numbers.

现在我的问题是,在code以下你可以声明一个数组如何我都做到了。

Now my question is, in the code below can you declare an array how I have done it.

{int n;
read(n);
int array[n];

......

......

或者这可以吗?

{int n; array[n];
read(n)

我想第一个是正确的。

I'm thinking the first one is correct.

先谢谢了。

推荐答案

在语法方面 - 这肯定是编程语言有关。但假设的编程语言表现或多或少静态并设为数组作为在存储器静态分配块(而不是载体,等)等则因为只有经过n被读出的静态数组可以分配第一个选项必须正确。

In terms of syntax - that would certainly be programming language dependent. But assuming the programming language behaves more or less statically and treats arrays as statically allocated blocks in memory (rather than vectors, etc.), etc. then the first option must be correct as only after n is read a static array can be allocated.

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

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