Can someone explain me what's is going on with this code.
class Point
{
private:
int x;
int y;
public:
Point(){}
void print(){
cout << x << " " << y << endl;
}
};
int main()
{
Point p;
p.print();
return 0;
}
If I run this code the output is -858993460 -858993460 witch is normal to me. It's garbage because I didn't initialize my 2 properties.
Here's the weird thing...
class Point
{
private:
int x;
int y;
int* buf;
public:
Point(){}
void print(){
cout << x << " " << y << " " << buf << endl;
}
};
int main()
{
Point p;
p.print();
return 0;
}
Now, I put the int* buf as a new class member and when I run this code, all my properties are initialized to zero. The output is 0 0 00000000. I'm using visual studio 2013 and I don't think this behavior was happening in Visual Studio 2010.
Can someone explain the logic behind that ?