+ 7
Explain static & dynamic objects in object oriented programming in C++???
🏵🌼💐🌸💮🏵💐🌼🏵🌸
2 ответов
+ 7
Objects are like any variable in essence blocks of memory, this memory is allocated either on the stack or on the heap.
Some like to call objects/vars that are allocated on the heap "dynamic".
But an object that is allocated on the stack basically works the same as one on the heap.
The only difference is that an object that is allocated on the stack has a known scope.
After an object allocated on the stack is no longer in scope it gets deleted and the memory that it had occupied gets freed.
An object allocated on the heap has an unknown scope, and in C++ the programmer must delete it manually, otherwise, you will create memory leaks.
But as I first said the "dynamic" labeling has nothing to do with OOP it's simply describing one way of using memory allocation.