Initialization of data members
In C++, class variables are initialized in the same order as they appear in the class declaration.
Consider the below code.
The program prints correct value of x, but some garbage value for y, because y is initialized before x as it appears before in the class declaration.
So one of the following two versions can be used to avoid the problem in above code.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.