Dynamic variables are not declared with ordinary variable declarations; they are explicitly allocated and deallocated at run time.
To allocate a single variable dynamically, we use the scalar (non-array) form of the new operator
When you use dynamic allocation, all the created variables are stored into heap, Heap memory is not managed automatically.
Whenever the function runs, its local variables are allocated. When the function exits, its locals are deallocated.
1.1 Dynamic Allocation Using new and delete. In C++, there are two operators to allocate and free memory
In the programs seen in previous chapters, all memory needs were determined before program execution by defining the variables needed.
• Dynamic variable is neither declared nor initialized, and has no identifier -- only reference is through pointer. • Created at runtime (ordinary variables created at compile time). • Operator new used to allocate memory for dynamic variable.
The scope resolution operator : : is a special operator that allows access to a global variable that is hidden by a local variable with the same name.
Dynamic Memory Allocation. We can dynamically allocate storage space while the program is running, but we cannot create new variable names "on the fly".
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.