之间
int array[100][100];
和
int array[100][100]={0};
在第一个中,当我打印数组的所有元素时,在第 94 行之后,中间,我开始获取垃圾值,但之前的所有值都是 0,而对于第二个,所有值为 0。
第一个声明不是也使用默认的 0 值进行初始化吗?如果没有,为什么数组中的所有值都不是垃圾值,为什么只有在第 94 行之后才出现垃圾值?
最佳答案
Does not the first declaration too initialize with a default 0 value?
没有。假设这是一个本地范围的变量,您的第一个声明根本不会导致任何初始化。
How come not all of the values in the array are garbage and why only after 94th row the garbage values are appearing?
未初始化的内存可以具有任何值,包括您正在观察的 0
值。
关于c - C 中两种不同数组初始化之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15521859/