Reputation: 1474
According to https://en.cppreference.com/w/cpp/language/default_initialization
"if T is an array type, every element of the array is default-initialized"
Am I misunderstanding something because as we all know http://www.cplusplus.com/doc/tutorial/arrays/
By default, regular arrays of local scope (for example, those declared within a function) are left uninitialized. This means that none of its elements are set to any particular value; their contents are undetermined at the point the array is declared.
...
The initializer can even have no values, just the braces: This creates an array of five int values, each initialized with a value of zero
How is the first source accurate and where can I find more credible documentation that addresses this behavior of array default initialization?
Upvotes: 2
Views: 77
Reputation: 51832
You need to read the whole thing. I numbered them:
The effects of default initialization are:
if T is a non-POD (until C++11) class type, the constructors are considered and subjected to overload resolution against the empty argument list. The constructor selected (which is one of the default constructors) is called to provide the initial value for the new object;
if T is an array type, every element of the array is default-initialized;
otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
It's a recursive statement. Every element in the array is default-initialized. What that means depends on the element type. If the element type is something 1. would apply to, then a default constructor is called for each element. But if the element type is, say, int
, then 3. happens. It's left with an indeterminate value.
Upvotes: 5
Reputation: 1
https://learn.microsoft.com/en-us/cpp/cpp/new-operator-cpp?view=vs-2019
new Operator is Reference MSDN.
Basically, inside the new operator, it consists of a function to be allocated and initialized by malloc. This is a function that is lapping with a new function.
Upvotes: -2