committed by
Quincy Larson
parent
b465d4e534
commit
8f6d076066
@ -17,7 +17,8 @@ title: Dynamic Memory Allocation
|
||||
`pointer-variable-type` = **new** `data-type;`
|
||||
Example 1: `int *ptr` = **new** `int;`
|
||||
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
|
||||
* 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