committed by
Quincy Larson
parent
b465d4e534
commit
8f6d076066
@ -18,6 +18,7 @@ title: Dynamic Memory Allocation
|
|||||||
Example 1: `int *ptr` = **new** `int;`
|
Example 1: `int *ptr` = **new** `int;`
|
||||||
Example 2: `int *ptr2` = **new** `int[10];`
|
Example 2: `int *ptr2` = **new** `int[10];`
|
||||||
Here, `pointer-variable-type` is a **pointer** of `data type`. The `data-type` can be int, char, etc. or user-defined data-type.
|
Here, `pointer-variable-type` is a **pointer** of `data type`. The `data-type` can be int, char, etc. or user-defined data-type.
|
||||||
|
* `new` is preferred over `malloc()` in C++ because new works for objects as well which is the main building block for OOPs.
|
||||||
|
|
||||||
### DELETE operator
|
### DELETE operator
|
||||||
* It is programmer's responsibility to de-allocate the dynamically allocated memory otherwise the memory would not be available to be re-allocated until the end of the program.
|
* It is programmer's responsibility to de-allocate the dynamically allocated memory otherwise the memory would not be available to be re-allocated until the end of the program.
|
||||||
|
Reference in New Issue
Block a user