Why those two scenarios (the initialization of A and of C ) produce different default initialization results in C++ 14? I can't understand the result based on the default initialization rules in cppreference.com
struct A { int m; };
struct C { C() : m(){}; int m; };
int main() {
A *a, *d;
A b;
A c{};
a=new A();
d=new A;
cout<<a->m<<endl;
cout<<d->m<<endl;
cout<<b.m<<endl;
cout<<c.m<<endl;
cout<<"--------------------"<<endl;
C *a1, *d1;
C b1;
C c1{};
a1=new C();
d1=new C;
cout<<a1->m<<endl;
cout<<d1->m<<endl;
cout<<b1.m<<endl;
cout<<c1.m<<endl;
}
Output:
(Scenario 1)
0
-1771317376
-1771317376
0
--------------------
(Scenario 2)
0
0
0
0
The post that tries to explain this (but it's not clear to me yet why the difference in the results and what causes m to be initialized in each scenario): Default, value and zero initialization mess