How can we create an object directly on heap instead of getting the same created on stack? Pl anyone can help here on this!!!! Thanks a lot.
Regards,
Sunil
How can we create an object directly on heap instead of getting the same created on stack? Pl anyone can help here on this!!!! Thanks a lot.
Regards,
Sunil
Hi,
(AFAIK) whenever any object is dynamically created it is stored in heap. For eg:
Code:
class A
{
A();
};
void fun(A * a)
{
a = new A();
}
How can we create an object directly on heap instead of getting the same created on stack? Pl anyone can help here on this!!!! Thanks a lot.
Regards,
Sunil
In C, you can make use of malloc(), calloc(), realloc() functions to
dynamically allocate memory so that they gets stored on heap.
In C++ you can use new to dynamically allocate memory so that they gets stored on heap.
Comment