What is the difference between new/delete and malloc/free?

前端 未结 15 2928
春和景丽
春和景丽 2020-11-21 23:53

What is the difference between new/delete and malloc/free?

Related (duplicate?): In what cases do I use malloc vs

15条回答
  •  春和景丽
    2020-11-22 00:07

    new and delete are operators in c++; which can be overloaded too. malloc and free are function in c;

    malloc returns null ptr when fails while new throws exception.

    address returned by malloc need to by type casted again as it returns the (void*)malloc(size) New return the typed pointer.

提交回复
热议问题