The first version allocates size bytes of storage space, aligned to represent an array object of that size (or less, if the implementation uses array overhead), and returns a non-null pointer to the first byte of this block. On failure, it throws a bad_alloc exception.
The second version is the nothrow version. It does the same as the first version, except that on failure it turns a null pointer instead of throwing an exception.
The third version is the placement version, that does not allocate memory - it simply returns ptr. Notice though that the constructor for the object will still be called.
Global dynamic storage operator functions are special in the standard library:
- All three versions of operator new[] are declared in the global namespace, not in the std namespace.
- The first and second versions are implicitly declared in every translation unit of a C++ program: The header <new> does not need to be included for them to be present.
- The first and second versions are also replaceable: A program may provide its own definition, that replaces the default one, to produce the result described above.