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?
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.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 forsome_obj_will be called 5 times. That should be trivial to verify. Depending on howsome_obj_is coded you may have a memory leak.