Hi All,

Is there any difference in the way object is created on stack and on heap?

I have come across a strange problem. Code snippet is as follows:

class A
{
private:
int a;
float b;
char c;

void Print()
{
cout<<"a = "<<a<<" b = "<<b<<" c = "<<c<<endl;
}
};

When I use
A *a = new A;
a->Print();
it compiles and prints some garbage values(as expected), which is fine.

But when I use
A a;
a.Print();
it gives compilation errors 1. 'a.A::a' is used uninitialized in this function 2. 'a.A::b' is used uninitialized in this function 3. 'a.A::c' is used uninitialized in this function

Can anyone please explain why is this happening??

Thanks