That depends on where the array is defined. If defined at file scope, its elements will be zero-initialized. If defined locally inside a function, its elements will have random values. But there is always an easy way to make sure an array is properly initialized:
Code:
// local array
void func()
{
char localCharArray[ 100 ] = {};
}
// at file scope
char arrayAtFileScope[ 100 ] = {};
// now a char array that is a class member
class MyClass
{
public:
MyClass() : m_memberArray()
{
}
private:
char m_memberArray[ 100 ];
};
P.S.: Relevant excerpt from the C++ standard:
3.6.2 Initialization of non-local objects
1) Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization
takes place. Zero-initialization and initialization with a constant expression are collectively called static
initialization; all other initialization is dynamic initialization.