Hi In example 1, member z will have a garbage value (i.e. 0 in your case )
Thanks Deepak On Sep 28, 2014 11:29 AM, "sagar sindwani" <[email protected]> wrote: > I am working on How compilers handle initialization list. I came across a > case where I am not sure what should be the compiler behaviour. > > *Example 1:-* > > #include <iostream> > > class A > { > public: > int x,y,z; > }; > > int main() > { > A a1[2] = > { > { 1,2 }, > { 3,4 } > }; > > std::cout << "a1[0].z is " << a1[0].z << std::endl; > > return 0; > } > > In above case a1[0].z is ? g++ shows it as 0 ( zero ). It is exactly 0 or > garbage value, I am not sure on that. > > I tried lot of books and some documents , no where I found what C++ says > for initialization of class objects. > > You can find handling of below case in almost every book. > > *Example 2:- * > > int arr[6] = {0}; > > In Example 2, compilers will auto-fill all members with 0. It is > mentioned in books. But when it comes to User-defined datatypes nothing is > mentioned. > > > Please share your thoughts on this. If you find any document related to > this, please share it as well. > > Thanks > Sagar > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
