For instance:
void Func()
{
int* i = new int; // the simplest case
vector<int*> v = new vector<int*>; // another case, not sure if **new** is using correctly here
vector<int*>* vPointer = new vector<int*>;
}
void main()
{
Func();
}
So, if I allocate dynamic memory(by using new operator) for local variables in functions,
- Do they live on heap or stack?
- when the program exits the function, are they still dangling around on heap or destroyed as function variables?
- Can I use new operator on non-pointer types? How to delete (or return back the allocated heap memory) it later?
Thank you!