I have the following code:
struct 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();
B b2;
print(b1);
print(b2);
return 0;
}
When I run the program (vs2008, debug), I have the following output:
x:0
y:0
--------
x:-858993460
y:-858993460
--------
As you can see, the values b1.x and b1.y have a value of 0. Why? What is the difference between init1 and init2?
When I uncomment constructor B, I have the following output:
x:-858993460
y:-858993460
--------
x:-858993460
y:-858993460
--------
Can someone explain the reason for this behavior? Tnx in advance.
source
share