3
#include <iostream>

using namespace std;

class A
{

    public:
        int x;
};

int main()

{

    A a = A();
    cout<<a.x<<endl;

}

For this code I am getting the output as 0 but when i create the object as A a; and then print a.x, I get garbage value. Why is this so?

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • I am trying to understand the behaviour of default constructor. Can anyone tell whether or not default constructor initializes member values to their default values? – Nitin Agarwal Aug 16 '17 at 19:36

0 Answers0