G
Gurikar
HI,
class A()
{
private:
int i;
char c;
public:
A();
};
void fun(A* a)
{
a = new A(); //allocated on heap(2nd time allocation)
}
int main()
{
A a; // allocated on stack
fun(&a);
}
Can you please tell wheather memory gets allocated 2 times for object
A(one on stack other on heap). Is this a valid code. Does both have
same adress(pointing to memory, even though both are on different
memory).. Atleast tell whats wrong in this code??
Regards
class A()
{
private:
int i;
char c;
public:
A();
};
void fun(A* a)
{
a = new A(); //allocated on heap(2nd time allocation)
}
int main()
{
A a; // allocated on stack
fun(&a);
}
Can you please tell wheather memory gets allocated 2 times for object
A(one on stack other on heap). Is this a valid code. Does both have
same adress(pointing to memory, even though both are on different
memory).. Atleast tell whats wrong in this code??
Regards