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

前端 未结 15 3046
春和景丽
春和景丽 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:20

    • new is an operator, whereas malloc() is a fucntion.
    • new returns exact data type, while malloc() returns void * (pointer of type void).
    • malloc(), memory is not initialized and default value is garbage, whereas in case of new, memory is initialized with default value, like with 'zero (0)' in case on int.
    • delete and free() both can be used for 'NULL' pointers.

提交回复
热议问题