Please explain to me if "x" is a Stack-Dynamic variable or Heap-Dynamic variable in this code?And if it is Heap-Dynamic then why it is not Stack-Dynamic variable?Thank you
function foo(){ MyClass x = new MyClass();}
Stack dynamic variables come into existence when you call a function. They exist on the C++ runtime stack, and are temporary. They are either in the parameter list, or declared inside the function (except for statics, which are not instantiated on the stack). These variables disappear when they go out of scope, and the memory for their contents is reclaimed by the runtime.
Heap dynamic instances exist in another area of memory the runtime sets aside called the "heap." These instances come into being via. the "new" operator, and must be explicitly deallocated by the "delete" operator.
I hope this is helpful
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With