int array[12];
This declares an array with 12 elements, not an empty array.
Furthermore it declares them without an initializer, which (in function scope) means that they will be default initialized. For int
that means no initialization is performed and the resulting int
s will have indeterminate values. This behavior is defined in the specification for C++.
If you want to zero initialize the array then you need to give it an initializer:
int array[12] = {};
The reason that this is not forced behavior is that there is a performance cost to initialization and some programs are written to work correctly without needing to suffer that penalty.