English 中文(简体)
Array in for loop, C99
原标题:Array in for loop, C99

我曾问过一个问题,即宣布一阵列为 lo。

for(i=0;i<=1000;i++){
    float arrayone[(length[i])];
    do a bunch of other stuff
}

基本上,我试图做一个阵列,其长度可根据方案的进展而有所不同。 我不想长期保存阵列数据(如阵列][]),因为数据是巨大的,而且有许多步骤。

因此,我被告知,只有在这种范围内才宣布阵列是合法的。 But将设法在月底前储存1,000份阵列,我不想这样做?。 我是一位开端人,因此我不理解各组成部分实际工作的细微差别。

我的另一种选择是,在目前最需要长的休息室之外打一个阵列,并超越每一步骤。

Edit:阵列的使用是:我有一个全球阵列。 用这一全球阵列填充功能结果,以节省计算费用。 这些阵列被操纵,......,并最终被用来改变全球阵列。 然后,他们再也不需要。

问题回答

但是,它是否会试图在我不想的末尾储存1,000份阵列?

无,在每一轮船开始时,将分配一个新的阵列,而且由于阵列在停泊时已超出范围,届时将进行分配,因此只有一个阵列。

这是自动变数点(这一阵列)。 在申报范围结束时(通常但并非总有分界线),它们自动处理。

每次更换后,所有在座标内宣布的变数都将销毁,包括你的阵列。 因此,将只保存一份你阵列的副本。

然而,可以说,你知道,在座外的阵列的初始化可能更好,因为你们几乎必须把记忆放在每一处。

如果你积极分配你的阵列(你不以你为榜样):

    for(i=0;i<=1000;i++){
      float * arrayone = (float*)malloc(i * sizeof(float));
    }

那么,你就有问题。 在这里,当地变量是点子,一旦被销毁,你就不再能够查阅所分配的记忆。 这是你一度以1,000个不同的记忆阵列结束的情况。 各位可在点子被销毁之前传承<条码>免费<>,但我坚持认为,在座标外宣布阵列仍然更好。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签