What happens if 'new' is used to instantiate an object without assigning it to variable?
c++, new-operator
Solution
new int[5];//without assigning it to a pointer.
Yes, there will be a `5*sizeof(int)` chunk of memory allocated but inaccessible to you, since you didn't save the pointer. You will have a memory leak.
new some_obj_[5];//without assigning it to a pointer.
Yes, there will be `5*sizeof(some_obj_)` chunk of memory allocated but inaccessible to you, since you didn't save the pointer. The default constructor for `some_obj_` will be called 5 times. That should be trivial to verify. Depending on how `some_obj_` is coded you may have a memory leak.
Problem
Want to ask what happens if I write the following and run the program. ``` new int[5]; // without assigning it to a pointer. ``` The compilation passed. But will there be a `5 * sizeof(int)` chunk of memory allocated? What if it is an object? ``` new some_obj_[5]; // without assigning it to a pointer. ``` Will the constructor of `some_obj_` be invoked?