Explain the difference between new/delete and malloc/free.
Last updated
new/deleteare type-aware operators that run constructors and destructors.malloc/freeonly manage raw bytes and return untypedvoid*.On failure
newthrowsstd::bad_allocwhilemallocreturnsnullptr. Onlynewcan be overloaded.Mixing them (e.g.
freeon anewed pointer) is undefined behavior. Prefer smart pointers in modern C++.