About dynamic memory in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

About dynamic memory in c++

// i want to create char dynamic memory char *test = new char; //okay, "new" statement will returning the dynamic memory address for char type //i want to create dynamic memory array of char char *test = new char[10]; with my logic, if we want to create array with dynamic memory, we should type "char** test". how can " char*" is working for both dynamic array, and not array? while if i want to create dynamic pointer, i should type: "char **test = new char*"

18th May 2018, 11:05 AM
Kevin AS
Kevin AS - avatar
1 Answer
Many times, you are not aware in advance how much memory you will need to store particular information in a defined variable and the size of required memory can be determined at run time. You can allocate memory at run time within the heap for the variable of a given type using a special operator in C++ which returns the address of the space allocated. This operator is called new operator. If you are not in need of dynamically allocated memory anymore, you can use delete operator, which de-allocates memory that was previously allocated by new operator.
18th May 2018, 12:14 PM