Initialization of allocated memory and allocation of arrays and objects using new and delete in C++

Memory can be initialized to a value by using a initialize.


p_variable = new variable_type (initializer);

Allocation of arrays can be done by:

p_variable = new array_type [size];

and to deallocate an array:

delete [ ] p_variable;

Objects are allocated dynamically by new to create a new object and return a pointer.

Leave a Reply