Added point in new keyword (#18546)

Added why new is preferred in C++
This commit is contained in:
Prem Kagrani
2018-10-15 02:36:07 +05:30
committed by Quincy Larson
parent b465d4e534
commit 8f6d076066

View File

@ -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.