分配数组的值未初始化 [英] value of allocated array not initialized
问题描述
如果我有
int array[20];
array [0]
的值是什么(如果尚未初始化)?有没有办法检查它是否已经初始化?
What is the value of array[0]
if nothing has been initialized there yet? Is there a way to check if it has been initialized?
推荐答案
"...假设我有..."您有哪里?
"...suppose I have..." You have it where?
如果在命名空间范围内有类似的内容,则它是一个具有静态存储持续时间的对象,该对象始终为零初始化.
If you have something like this in namespace scope, then it is an object with static storage duration, which is always zero-initialized.
如果在本地范围内有这样的对象,则它是一个具有自动存储持续时间的对象,该对象根本没有初始化. array [0]
的值是不可预测的.不,没有办法告诉您是否已对某些内容进行了初始化.
If you have something like this in local scope, then it is an object with automatic storage duration, which is not initialized at all. The value of array[0]
is unpredictable. And no, there's no way to tell whether something has been deliberately initialized or not.
这篇关于分配数组的值未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!