I have following C++ code. Since, the memory is dynamically allocated, it should be allocated on heap. Or, since the memory has been allocated right at time of declaration and not in any constructor, is it being allocated on stack? And do I need a de-constructor to free the memory?
class param{
public:
char* st = new char[256];
};
What happens in the following scenario? I guess this is allocated on stack, and need not to be freed using a deconstructor.
class param{
public:
char st[256];
};
Third way is to write it as:
class param{
public:
char* st;
param()
{
st = new char[256];
}
~param()
{
delete[] st;
}
};
Which one of the three above is the correct way to do it?