关于C中循环数组的重新声明 [英] Redeclaring of an array in loop in C

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

问题描述

在一个循环套申报为零时不阵列时的循环重复?

Doesn't the array when declared in a loop sets to zero when the loop repeats?

我有一个数组,并使用它这样..

I have an array and working with it this way..

while(i<n)
{
    int a[1000];
    //taking inputs in array..
    /*some calculations with array..
    the values in array may change*/
}

在循环重复,阵列中的再次声明下一次,它是一个新的数组,所以不在阵零值现在?

The next time when the loop repeats, array a is declared again, it is a new array, so aren't values in array zero now?

其实我有一个做了code这种方式,并指出,该值不为0,而是都一样,他们只是在循环重复之前是。为什么呢?

Actually I have a made a code this way and observed that the values are not zero but instead are same as they were just before the loop repeats. Why?

推荐答案

数组的值是未初始化的,它们所包含的随机垃圾的那名价值观堆栈。

The values of the array are uninitialized, they contain the "random" junk values that were on the stack.

另外,阵列中的数据可能在各循环运行被覆盖。即如果你需要的值留在环路之间不变,然后扯起,而循环之前数组声明。

Also the numbers in the array might be overwritten in each loop run. I.e. if you need the values to stay unaltered between the loops, then hoist the array declaration before the while loop.

使用

int a[1000] = {0};

要初始化为零的数组。

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

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