I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc
you should call free
and when you use the
new vs malloc()
1) new
is an operator, while malloc()
is a function.
2) new
calls constructors, while malloc()
does not.
3) new
returns exact data type, while malloc()
returns void *.
4) new
never returns a NULL (will throw on failure) while malloc()
returns NULL
5) Reallocation of memory not handled by new
while malloc()
can