Circle is a class, with public method GetDiameter().
What is the difference between the following 2 sets of code?
Qn1: Does Method 1 allocates memory for c on stack (hence no need free memory), while Method 2 allocates memory for c on heap (need manually free memory)?
Qn2: When should we use Method 1 or Method 2?
Method 1:
void Init()
{
Circle c;
c.GetDiameter();
return;
}
Method 2:
void Init()
{
Circle *c = new Circle();
c->GetDiameter();
return;
}