This is a simple question, but I can’t seem to find a definitive answer.
If we have the following class:
class Test
{
...
char testArray[10];
...
};
When we create an instance of Test, what is the default value of testArray[1]?
If it was a local array, it would be uninitialized.
If it was a static array, it would be initialized to 0.
What does it do when the array is a class member?
From the standard, section 8.5
[dcl.init]:also section 12.6.2
[class.base.init]:So because the element type is
char, when each element is default-initialized, no initialization is performed. The contents are left with arbitrary values.Unless, of course, it’s a member of an instance of the class, and the instance has static storage duration. Then the whole instance is zero-initialized, array members and all, before execution begins.