How do new/delete, operator new, and malloc/free differ in storage allocation, object lifetime, construction, failure, alignment, and replacement?
Show answer and explanation
A new-expression obtains suitably aligned storage through an allocation function such as operator new and then constructs the requested object; if construction throws, the matching deallocation function is called. A delete-expression destroys the object and then invokes matching operator delete. Direct operator new manages raw storage only and normally throws bad_alloc on failure, while malloc returns raw bytes and reports failure with null; malloc/free do not run constructors or destructors, and over-aligned requests need an appropriate API. Mixing allocation and deallocation families or using the wrong array form is undefined behavior. Replaceable global allocation functions have strict signatures and pairing rules; application code should normally prefer RAII owners and containers.
A new-expression obtains suitably aligned storage through an allocation function such as operator new and then constructs the requested object; if construction throws, the matching deallocation function is called. A delete-expression destroys the object and then invokes matching operator delete. Direct operator new manages raw storage only and normally throws bad_alloc on failure, while malloc returns raw bytes and reports failure with null; malloc/free do not run constructors or destructors, and over-aligned requests need an appropriate API. Mixing allocation and deallocation families or using the wrong array form is undefined behavior. Replaceable global allocation functions have strict signatures and pairing rules; application code should normally prefer RAII owners and containers.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.