Why do these two scenarios (initialization A and C) create different default initialization results in C ++ 14? I cannot understand the result based on the default initialization rules at 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<<bm<<endl; cout<<cm<<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
A message that tries to explain this (but I still donโt understand why the difference in results and the reasons why m will be initialized in each scenario): Default value, value and zero initialization mess
c ++ initialization default-value c ++ 14
darkThoughts Jul 24 '17 at 21:10 2017-07-24 21:10
source share