Why following code produced 0 as output? In my understanding, it is default initialization (not value initialization) so value should be random.
#include <stdio.h>
#include<iostream>
#include<memory>
using namespace std;
struct A
{
int i;
int j;
};
int main()
{
A a;
cout << " i is " << a.i << endl;
return 0;
}
from cppreference:
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.
0as random as any other number? - 463035818_is_not_a_number0is an invalid random value? - Algirdas Preidžius