dynamic memory | Sololearn: Learn to code for FREE!


dynamic memory

how we allocate dynamic memory ?

6/20/2018 7:10:22 PM


5 Answers

New Answer


hinanawi It's not considered good practice to manually allocate and deallocate memory with those functions. C++ best practice to use smart pointers like unique_ptr and shared_ptr


malloc/free/realloc in C++ must be used ONLY for raw memory allocation while for objects you have to use new/delete


for memory manipulation you would use malloc(), realloc(), and free(), if that's your question.


ok thanks


Actually i want help in program which consists of a class Pyramid. The class should contain a static data member “Pcount” which stores the total number of Pyramid’s objects. In the main() function, dynamically create three objects of Pyramid class and print the value of “Pcount”. Afterwards, delete any two objects of Pyramid and print the value of “Pcount” again. Can anyone help me with coding .