If I have:
int array[20];
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.
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.
What is the value of array[0] supposing nothing has been initialized there yet?
It depends whether the array is defined in the file scope or in the function scope. In function scope array elements would contain unspecified values whereas in file scope they would be zero initialized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With