I have the following code:
struct B
{
//B() {}
int x;
int y;
};
void print(const B &b)
{
std::cout<<"x:"<<b.x<<std::endl;
std::cout<<"y:"<<b.y<<std::endl;
std::cout<<"--------"<<std::endl;
}
int main()
{
B b1 = B(); //init1
B b2; //init2
print(b1);
print(b2);
return 0;
}
When I start program (vs2008, debug) I have the following output:
x:0
y:0
--------
x:-858993460
y:-858993460
--------
As you can see b1.x and b1.y have 0 value. why? What's difference between init1 and init2?
When I uncomment B constructor I have the following output:
x:-858993460
y:-858993460
--------
x:-858993460
y:-858993460
--------
Can somebody explain the reason of this behaviour? Tnx in advance.