What is the functional difference between myObj *x = new myObj[100]; delete x; and myObj *x = new myObj[100]; delete [] x;
Reveal answer
Fill a bubble to check yourself
What is the functional difference between myObj *x = new myObj[100]; delete x; and myObj *x = new myObj[100]; delete [] x;
There is none; they both work as expected
They both do nothing.
The first will not invoke all myObj destructors
It would'nt delete all the memory allocated to the objects
The delete[] operator is required for arrays because it invokes the destructor for every element in the array. Using plain delete only invokes the destructor for the first element (myObj) and not the remaining 99 objects, causing resource leaks. The pairing must be new[] with delete[] and new with delete.
When you allocate an array with new myObj[100], you must deallocate it with the array form delete[] x, which tells the runtime to call the destructor for every element in the array. Plain delete x only calls the destructor for the first element (and its behavior for the rest is technically undefined) and typically still frees the underlying memory block, so the functional difference is in destructor invocation, not necessarily total memory reclamation.